gradient can be used as background for TextView

list_grad.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="@color/gradient_start" android:endColor="@color/gradient_end" android:angle="-270" /> </shape> 

...

 <TextView android:id="@+id/ranking_order" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/list_grad" /> 

Is it possible to make such a background through shape?

enter image description here

added:

Is it possible to set a complex shape for the ProgressBar, as shown?

enter image description here

I think through the Canvas you can do something similar. If you first draw a progress bar, and then cut out the shape using a mask. But will it not be too difficult?

  • one
    Do you need something like that ? then one shape is not enough then - pavlofff
  • @pavlofff, thanks for the example - ravend
  • @pavlofff, is it possible to set a complex shape for the ProgressBar? (expanded question) - ravend
  • one
    Yes, you can, see you just do for example VIew element. And you have the usual Progress Bar. Then you make a transparent form in the form of a machine. For example, this ImageView stretches it over the entire View element from above, it turns out that the progress bar will work as well, but from above it will be closed by a machine that is transparent in the center. Get the effect you want, and yes, this is a very simple operation. - Shwarz Andrei
  • @ShwarzAndrei, thanks for the reply. Is it possible to achieve a transparent background? I need to place this item on another image. - ravend

1 answer 1

In theory, you can:

  <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#08a303" /> <corners android:radius="20dp"/> </shape> </item> <item android:bottom="320dp"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#FFF" /> <corners android:topLeftRadius="20dp" android:topRightRadius="20dp"/> </shape> </item> </layer-list> 

enter image description here