3

这就是我要的:

在此处输入图像描述

这就是我所做的:

在此处输入图像描述

不同之处在于线条和边框之间有一些空格,因为我用于padding=10dp外边框:

<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"/>
    <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp"/>
</shape>

我这样做对吗?我该如何解决这个问题?

4

3 回答 3

4

这是您想要的 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>

在此处输入图像描述

于 2012-09-13T08:18:53.780 回答
1

移除填充物。将元素放入每个框中,并为每个框添加填充。

于 2012-09-13T08:08:29.877 回答
1

解决方案1: //删除形状的填充

解决方案2: //保持填充不变

并为您的视图设置边距,即您正在绘制的那条线作为水平线

android:marginLeft="-10dp"
android:marginRight="-10dp"

//对于最上面的

android:marginTop="-10dp"
于 2012-09-13T08:15:08.683 回答