Issue
I want to make some Drawable as a background of a TextView. The TextView length will be vary and I want the Drawable to expand with the TextView. I set the Drawable as the background of the TextView but it looks weird.
this is my TextView:<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:textColor="#ffffff"
/>
and this is my @drawable/background. It is just a round shape vector:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
>
<path
android:fillColor="#80000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2z"
/>
</vector>
I want the drawable to expand with the TextView length (it might have more than one line) but keep the shape of the edge (rounded). How can I do that?
Solution
Create shape drawable as per below :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/yourgraycolor" />
<padding android:top="@dimen/margin_vsmall" android:bottom="@dimen/margin_vsmall" android:left="@dimen/margin_small" android:right="@dimen/margin_small" />
<corners
android:radius="@dimen/radius" />
</shape>
And apply to your textview as background android:background="@drawable/yourshapedrawable
Here adjust your radius and padding as per your need.
Answered By - Jai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.