gpt4 book ai didi

安卓 : adding border around textview

转载 作者:IT老高 更新时间:2023-10-28 23:20:51 26 4
gpt4 key购买 nike

如何使用 xml 布局在文本周围添加边框,如图所示

image 1

我尝试在布局中添加边框,但它与文本重叠。

image 2

最佳答案

你可以试试这个布局,它会根据你的要求反射(reflect)出来

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="15dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Label 1: Value 1"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Label 2: Value 2"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Label 3: Value 3"/>

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text=" Details "
android:layout_marginLeft="15dp"
android:background="#ffffff"
android:textSize="17sp" />

</RelativeLayout>

border.xml的xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#cdcdcd" />
</shape>

希望这对您有所帮助。

关于安卓 : adding border around textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38787794/

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