【问题标题】:how to add space between views in RelativeLayout如何在RelativeLayout中的视图之间添加空间
【发布时间】:2018-02-03 21:30:42
【问题描述】:

如何在RelativeLayout 组中的视图之间添加空格?

在使用Layout_marginBottompaddingBottom 对齐Button 顶部的TextView 之后,我试图在TextViewButton 之间添加一个空格,但它们都不起作用。

代码如下:

<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text=" Drawing ... "
android:gravity="center_horizontal"
android:layout_alignTop="@id/reset"
android:layout_marginBottom="50dp" />

<Button
    android:id="@+id/reset"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:onClick="reset"
    android:text="Reset" />

谢谢。

【问题讨论】:

    标签: android xml alignment android-relativelayout


    【解决方案1】:

    试试这个。

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:text=" Drawing ... "
        android:gravity="center_horizontal"
        android:layout_above="@+id/reset"
        android:layout_marginBottom="15dp"/>
    
    <Button
        android:id="@+id/reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="reset"
        android:text="Reset"
        android:layout_alignParentBottom="true"/>
    

    【讨论】: