如果相对布局具有后台资源,则layout_below / layout_above不起作用

时间:2013-07-10 10:40:54

标签: android android-layout

第一种情况......相对布局没有背景可绘制资源集...以下代码完全按预期工作,屏幕截图附加enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentLayout">

    <Button android:text="Jill"
    android:id="@+id/btnJill"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"/>

<Button
    android:id="@+id/btnJack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Jack"
    android:layout_below="@id/btnJill"/>

</RelativeLayout>

第二种情况......相对布局有一个背景可绘制的资源集...现在只需添加一行就可以搞清楚结果,附上截图!enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parentLayout"
android:background="@drawable/background">
    <Button android:text="Jill"
    android:id="@+id/btnJill"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"/>

<Button
    android:id="@+id/btnJack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Jack"
    android:layout_below="@id/btnJill"/>

</RelativeLayout>

这必须是一个错误......如果没有人有解决方案。

1 个答案:

答案 0 :(得分:0)

android:layout_below="@id/btnJill"更改为android:layout_below="@+id/btnJill"