Layer-List drawable as background does not completely fill its Android view

268 Views Asked by At

I have been working with a Layer-List drawable for some time now.

I am not really understanding why the drawable does not fit the dimensions of the Textview. Only after I set android:background="some color" and android:drawableTop="@drawable/myxml_drawable" is when I began to see the drawable was all over the place of this textview.

First I just had: android:background="@drawable/myxml_drawable" doing this will clip the top part of the drawable even though I matched the specifications of the size that was used in creating the xml drawable.

See the picture of the drawable below( purple arrow) and the textview has been colored black.

enter image description here

The only reason why the drawable looks centered in the background of this textview is cause I used paddingTop and paddingLeft to fix the appearance.

Here is how the textview is laid out in its constraintlayout

 <TextView
    android:id="@+id/uppy_arrow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/grandstander_extrabold"
    android:gravity="bottom|fill_horizontal"
    android:text="@string/add_string"
    android:textColor="@color/purple_200"
    android:drawableTop="@drawable/uppy_arrow"
    android:paddingTop="43dp"
    android:paddingLeft="9dp"
    android:background="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/my_image_view"
    app:layout_constraintLeft_toLeftOf="@id/t2"
    app:layout_constraintRight_toRightOf="@id/t2"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.99"
    app:layout_constraintHorizontal_bias="0.5"
    />

How can I use this xml drawable as the background of this textview and make sure it fills the size of the textview as much as possible so that the text will be centered on it?

1

There are 1 best solutions below

5
Narendra_Nath On
  1. Please check the drawable itself. Make sure there is no inherent padding to it.Use vectors.
  2. If you're using png or any other format makes sure the scaletype paramter is set to a legit value like fitXY or centerCrop
  3. To center the text inside the image.You can also have a imageview separately and superimpose your textview on it