如何在 Android 视图中的圆角矩形内插入文本?
我需要创建以下视图。我有以下 XML,但文本没有显示,并且高度填充了整个父级而不是包裹内容?任何有关创建以下屏幕截图的帮助将不胜感激。
play.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>
I have the below view that I need to create. I have the following XML, but the text does not show up and the height fills the entire parent instead of wrapping the content? Any help on creating the below screenshot 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您必须为圆角边缘创建一个 xml 文件,然后创建一个线性布局并在该背景中设置该圆角边缘,然后动态地将文本视图添加到该特定线性布局。
这里我附上了我的圆边 xml 文件
First you have to create a one xml file for rounded edges, then create a one linear layout and set that rounded edges in that back ground and then dynamically add text view to that particular linear layout .
Here i attached my rounded edge xml file
为了更好地设计视图,请为每个视图采用 3 个单独的形状,以便更轻松地设计 UI 并对齐每个形状的文本。
For a better design of your views, take 3 individual shapes for each view so that it is easier to design the UI and align the text for each shape.