2014-02-27 39 views
0

我試圖在左側位置的新圖層中添加片段下方的紅色按鈕(android:id="@+id/button8),但它無法響應,仍然位於圖片頂部:如何在左下方的新圖層中添加按鈕

XML文件

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="bottom" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" > 

<LinearLayout 
    android:id="@+id/topLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:orientation="horizontal" > 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="38dp" 
     android:layout_height="30dp" 
     android:background="#000000"/> 

</LinearLayout> 

<fragment 
    android:id="@+id/fragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/topLayout" /> 

<LinearLayout 
    android:id="@+id/ttt" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:orientation="horizontal" > 

<Button 
    android:id="@+id/button8" 
    android:layout_width="38dp" 
    android:layout_height="30dp" 
    android:background="#FF0000" /> 
</LinearLayout> 

回答

0

注意,RelativeLayout的不採取考慮的順序你把你的元素放入你的xml中。對於那個使用LinearLayout。在你的情況下,你必須指定你的佈局在frament之後。

試試這個:

<fragment 
    android:id="@+id/fragment" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@+id/ttt" 
    android:layout_below="@id/topLayout" /> 

<LinearLayout 
    android:id="@+id/ttt" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:gravity="left" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/button8" 
     android:layout_width="38dp" 
     android:layout_height="30dp" 
     android:background="#FF0000" /> 
</LinearLayout> 
+0

在頂部 – user3350437

+0

不行,仍然可以看到修正後的版本。 'layout_below''' below'' – cosmincalistru

+0

我嘗試更正的代碼,但按鈕消失,我可以看到它的位置 – user3350437

相關問題