How to insert text inside a rounded rectangle and Android?

I have a view below that I need to create. I have the following XML, but the text is not displayed, and the height fills the entire parent instead of packing the content? Any help on taking a screenshot below would be appreciated.

playing.xml

<View android:background="@drawable/rounded_edges" android:text="Current Track" android:textColor="#FFFFFF" android:id="@+id/current_track" android:layout_width="fill_parent" android:layout_height="wrap_content" android:editable="false"> </View> 

rounded_edges.xml

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#1F1F1F"/> <corners android:radius="5px"/> <padding android:left="20dp" android:top="20dp" android:right="20dp" android:bottom="20dp" /> </shape> 

view

+4
source share
2 answers

First you need to create one xml file for the rounded edges, then create one linear layout and set the rounded edges in this back margin, and then dynamically add a text representation to this particular linear layout.

  <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/your_rounded_edges_xml_file" android:orientation="vertical" android:layout_marginRight="10dp" android:id="@+id/linearLayout"> </LinearLayout> 

Here I attached my rounded edge XML file

 <?xml version="1.0" encoding="UTF-8"?> 

 <stroke android:width="1dp" android:color="#ababab" /> <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 

+4
source

For a better design for your views, take 3 separate shapes for each view, so it’s easier to create a user interface and align text for each shape.

0
source

Source: https://habr.com/ru/post/1342755/


All Articles