0

I try to add a textview to a relative layout at position 0,0 !

Following code is used:

TextView text = new TextView(getActivity());
    text.setTextColor(Color.RED);
    text.setIncludeFontPadding(false);
    text.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, 32 * getResources().getDisplayMetrics().density);
    text.setText("TEST TEXT");
    text.setSingleLine(false);
    text.setX(0);
    text.setY(0);
    text.setTypeface(fct.getFont().getTypeFace(getActivity())); container.addView(text); 

container is a relative layout defined here:

<RelativeLayout
    android:id="@+frontcard/container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    />

I use a custom font with the textview...

The problem is that the text view is not displayed correctly. There is a padding to the top ... left is set correct.

Image for the output:

Image as Textview

If i draw it on a canvas everything works fine like this image shows:

Image as Bitmap

Do i have a problem with the custom font in a textview ?

Anyone has any ideas ?

Chrissss
  • 97
  • 8
  • im not sure but the TextView has a natural margin in top and bottom, try text.setGravity(Gravity.TOP); – Akariuz May 26 '15 at 16:30
  • Great idea... unfortunately it is not working :/ I guess there is something with the padding of the custom font – Chrissss May 26 '15 at 16:53

1 Answers1

0

try adding

text.setIncludeFontPadding(false);