这是您想要的 xml 文件。
从您的 xml 文件中删除 Padding 并将填充放在每个小部件中。这里 test.xml 是没有填充属性的背景 xml 文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:background="@drawable/test"
android:layout_margin="10dp">
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sample TextView"
android:padding="10dp"/>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sample TextView"
android:padding="10dp"/>
</LinearLayout>
编辑test.xml 文件
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#808080"/>
<corners
android:radius="10dp"/>
</shape>
![在此处输入图像描述](https://i.stack.imgur.com/SUdMk.png)