2014-02-27 2 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. В вашем случае вы должны указать, что ваш макет после взлома.

Попробуйте это:

<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' не' ниже' – cosmincalistru

+0

Я пытаюсь скорректировать код, но кнопка исчезает, и я могу, я вижу, где ее позиция – user3350437

Смежные вопросы