Expiredmind
Expiredmind

Reputation: 808

add padding to textView with drawable background

Is it possible to add padding into TextView with drawable element on its backround? Or do I need to use Draw 9-patch ?

<TextView
    android:layout_width="wrap_content"
    android:layout_gravity="bottom|left"
    android:layout_marginLeft="5dp"
    android:layout_height="85dp"
    android:background="@drawable/text_background"
    android:id="@+id/counter"
    android:textColor="@color/white"
    android:textSize="12sp"
    android:textStyle="bold"
    android:gravity="center"
    android:paddingLeft="2dp"
    android:paddingRight="2dp"
/>

This padding settings does not work. For 3-4 digits the background is displayed correctly but when it should adjust (for 5/6 digits) it stays the same.
UPDATE - add image
enter image description here

Upvotes: 1

Views: 2043

Answers (1)

Ashish M
Ashish M

Reputation: 823

If You are adding drawable as background then drawablePadding doesn't works.

You just have to give proper padding to you TextView, so that it can handle most of your usecases.

<TextView
    android:id="@+id/txt_bankid_login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/layout_user_detail"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/spacing_huge"
    android:background="@drawable/textview_selector"
    android:clickable="true"
    android:textAllCaps="true"
    android:padding="@dimen/spacing_small"
    android:text="@string/login_bankid"
    android:textColor="@color/app_background_color"
    android:textSize="@dimen/font_normal" />

Never give static height or width to your layouts as you have used in height. It will create problem in different screens and you will face text cutoff.

Upvotes: 1

Related Questions