我正在尝试在TextVIEw上设置Roboto light字体.
我从here下载了Roboto字体.
我从代码中做的就是:
sRobotoItalic = Typeface .createFromAsset(getContext().getAssets(), "Fonts/Roboto_v1.2/Roboto-Italic.ttf");final TextVIEw textVIEw = (TextVIEw) vIEw.findVIEwByID(R.ID.text_vIEw);textVIEw.setTypeface(sRobotoItalic);
并且我的TextVIEw的高度几乎变为实际文本高度的5倍.
我确定这是我的TextVIEw,而不是其他一些视图来改变它的大小(使用背景颜色)和那个特定的字体导致问题(我试图在我的TextVIEw上设置不同的字体,当我使用时没有错他们).
现在,我找到了解决这个问题的方法
sRobotoItalic = Typeface .createFromAsset(getContext().getAssets(), "Fonts/Roboto_v1.2/Roboto-Italic.ttf");final TextVIEw textVIEw = (TextVIEw) vIEw.findVIEwByID(R.ID.text_vIEw); textVIEw.addOnLayoutchangelistener(new VIEw.OnLayoutchangelistener() { @OverrIDe public voID onLayoutChange(VIEw v, int left, int top, int right, int bottom, int oldleft, int oldtop, int oldRight, int oldBottom) { int height = v.getHeight(); mTypefaceUtils.setRobotoItalicTypeFace(passedExamsLabel); ((TextVIEw) v).setHeight(height); } });
但这更像是一个解决方案.如果有更多文本视图具有同样的问题,代码会很快变得混乱.
这是TextVIEw xml(第二个)
<relativeLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_marginBottom="@dimen/marginBottom" androID:layout_marginleft="4dp" androID:layout_marginRight="4dp" androID:layout_margintop="@dimen/margintop" androID:padding="4dp"> <TextVIEw androID:ID="@+ID/text_vIEw" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentleft="true" androID:layout_centerInParent="true" androID:layout_marginleft="5dp" androID:textStyle="italic" androID:textSize="@dimen/text_size" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentRight="true" androID:layout_marginRight="10dp" androID:text="0" androID:textSize="@dimen/text_size" androID:textStyle="italic" /> </relativeLayout>
难道我做错了什么?我该怎么修?
解决方法:
好吧,不要使用谷歌提供的字体,但那些:https://github.com/android/platform_frameworks_base/tree/master/data/fonts
我从手机中取出字体(N5,5.0),效果很好.
总结以上是内存溢出为你收集整理的android – 当我使用Roboto-Italic.ttf字体时,为什么TextView.setTypeface()夸大地增加了我的TextView高度?全部内容,希望文章能够帮你解决android – 当我使用Roboto-Italic.ttf字体时,为什么TextView.setTypeface()夸大地增加了我的TextView高度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)