2012-02-13 8 views
0

Используя как относительные, так и линейные макеты, как у меня есть текстовое поле в верхней части макета, расположенного по горизонтали, а внизу есть 4 кнопки, которые отображаются в одной строке с равным пространством между ними.макет андроида - верхняя и нижняя

+3

Ваш вопрос звучит так, как будто кто-то дал вам это как домашнюю работу, вы должны попробовать это самостоятельно, а затем, если вы все еще сталкиваетесь с трудностями, задайте вопрос с тем, что вы пробовали до сих пор. – triggs

ответ

2
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" > 

     <requestFocus /> 
    </EditText> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:gravity="center_horizontal" > 

     <Button 
      android:id="@+id/btn1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="btn 1 " /> 

     <Button 
      android:id="@+id/btn2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/btn1" 
      android:text="btn 2 " /> 

     <Button 
      android:id="@+id/btn3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/btn2" 
      android:text="btn 3 " /> 

     <Button 
      android:id="@+id/btn4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/btn3" 
      android:text="btn 4 " /> 
    </RelativeLayout> 

</RelativeLayout> 
+0

хороший ответ, делает именно то, что я спросил. как я мог бы центрировать по горизонтали эти кнопки внизу? – user706315

+0

см. Обновить мой ответ –

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello Android!" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentTop="true"/> 

    <LinearLayout 
     android:layout_alignParentBottom="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Button1" 
      android:layout_weight="1" /> 
     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Button2" 
      android:layout_weight="1" /> 
     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Button3" 
      android:layout_weight="1" /> 
     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Button4" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</RelativeLayout> 
1

Для верхней кнопки, вы можете сделать это с помощью графического интерфейса Layout. Просто добавьте текстовое поле и установите его следующие свойства:

android:layout_alignParentTop="true" 
android:layout_centerHorizontal="true" 

Для нижних кнопок вы должны добавить LinearLayout со следующими свойствами:

android:layout_alignParentBottom="true" 
android:layout_width="fill_parent" 

и положить 4 кнопки с android:layout_weight="1" внутри.

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