生成(在代码中)Gmail中的字母化身的最佳方法是什么?
这里有一个例子
https://drive.google.com/folderview?id=0B0Fhz5fDg1njSmpUakhhZllEWHM&usp=sharing
看起来应该是这样的:
解决方法:
这就是我曾经使用过的…请根据您的要求尝试修改.
public class Letteravatar extends colorDrawable {Paint paint = new Paint();Rect bounds = new Rect();String pLetters;private float ONE_DP = 0.0f;private Resources pResources;private int ppadding;int pSize = 0;float pMesuredTextWIDth;int pBoundsTextwIDth;int pBoundsTextHeight;public Letteravatar (Context context, int color, String letter, int paddingInDp) { super(color); this.pLetters = letter; this.pResources = context.getResources(); ONE_DP = 1 * pResources.getdisplayMetrics().density; this.ppadding = Math.round(paddingInDp * ONE_DP);}@OverrIDepublic voID draw(Canvas canvas) { super.draw(canvas); paint.setAntiAlias(true); do { paint.setTextSize(++pSize); paint.getTextBounds(pLetters, 0, pLetters.length(), bounds); } while ((bounds.height() < (canvas.getHeight() - ppadding)) && (paint.measureText(pLetters) < (canvas.getWIDth() - ppadding))); paint.setTextSize(pSize); pMesuredTextWIDth = paint.measureText(pLetters); pBoundsTextHeight = bounds.height(); float xOffset = ((canvas.getWIDth() - pMesuredTextWIDth) / 2); float yOffset = (int) (pBoundsTextHeight + (canvas.getHeight() - pBoundsTextHeight) / 2); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BolD)); paint.setcolor(0xffffffff); canvas.drawText(pLetters, xOffset, yOffset, paint);} }
然后在imagevIEw.setdrawable中设置新的Letteravatar(context,colorCode,letters,padding)
总结以上是内存溢出为你收集整理的像Gmail Android最佳实践的字母头像全部内容,希望文章能够帮你解决像Gmail Android最佳实践的字母头像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)