gpt4 book ai didi

android - 如何在 Android View 中的圆角矩形内插入文本?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:09:09 25 4
gpt4 key购买 nike

我需要创建以下 View 。我有以下 XML,但文本没有显示,高度填充整个父级而不是包装内容?任何有关创建以下屏幕截图的帮助将不胜感激。

播放.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

最佳答案

首先,您必须为圆形边缘创建一个 xml 文件,然后创建一个线性布局并在该背景中设置该圆形边缘,然后动态地将 TextView 添加到该特定线性布局。

    <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>

这里我附上了我的圆边 xml 文件

<?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"/>

关于android - 如何在 Android View 中的圆角矩形内插入文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5228783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com