I am trying to set Roboto Light font on TextView. I downloaded Roboto fonts from here .
All I do from my code:
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);
and the height of my TextView changes will be almost 5 times the height of the actual text.
I am sure that this is my TextView, and not some other view, to resize it (played with background colors) and that this particular font causes a problem (I tried installing different fonts in my TextView, and nothing happened when I had them used).
Now I have found a fix for this
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);
}
});
but it's a hack more than a solution. Code becomes messy if there is more textual representation with the same problem.
This is a text xml (second)
<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>
- ? ?