【问题标题】:Horizontal line padding水平线填充
【发布时间】:2011-04-19 00:20:04
【问题描述】:

我试图在两个 EditText 小部件之间添加一条水平线,但奇怪的是,这条线的底部没有填充,所以它看起来“粘”在它下面的小部件上。

这是我的代码(在 layout.xml 中,在垂直方向的 LinearLayout 中):

    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:capitalize="sentences"
        android:singleLine="true"
        android:maxLength="30" />
    <View android:background="#FF00FF00" 
        android:layout_width="fill_parent"
        android:layout_height="1dip" />
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:scrollbars="vertical"
        android:capitalize="none"
        android:autoLink="all"
        android:maxLines="8" />

这就是它的样子:

我想在该行下方添加一些填充。我尝试在 View 小部件中使用 android:paddingBottom,并在下面的 EditText 小部件中使用 android:paddingTop,但结果是相同的(它被忽略了)。

【问题讨论】:

    标签: android


    【解决方案1】:

    使用 ma​​rgin 代替填充。 在 xml 中使用以下属性:

    android:layout_marginTop="5dip"
    android:layout_marginBottom="5dip"
    

    希望这能解决您的问题...:)

    【讨论】:

      【解决方案2】:

      改为使用边距。填充是视图内内容周围的区域。例如,如果为 EditText 提供填充,则会增加框的大小(文本周围的区域),但不要在其周围留出任何空间。

      【讨论】:

      • 你是对的。我用 android:marginBottom 进行了测试,因为我认为它与 android:paddingBottom 有关,但它不存在。在边距中,它需要名称中的“布局”部分,即 android:layout_marginBottom ......这非常令人困惑......
      • 这需要习惯。 “layout_”之所以是名称的一部分,是因为边距是视图“布局参数”的一部分,而不是视图的各个属性。
      • 感谢您的澄清 :)