2010-11-23 2 views
0

У меня есть 4 LinearLayout s, которые я бы хотел преобразовать в RelativeLayout s. Используя мой xml здесь, я, как мой предпочтительный формат:Как легко конвертировать мои LinearLayouts в RelativeLayouts

  • ImageButton
  • ImageButton
  • TextView
  • Кнопка

Как изменить в RelativeLayout, чтобы всегда отображать 1-ImageButton на самом верху, всегда показывайте Button в самом низу, и у вас есть второй ImageButton ниже первого ImageButton, с TextView между 2-м ImageButton и обычным Button?

Спасибо!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:gravity="center"> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/image_view" /> 

    <TextView 
     android:text="@+id/TextView01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/message" /> 

    <Button 
     android:layout_gravity="center_horizontal" 
     android:layout_width="fill_parent" 
     android:textStyle="bold" 
     android:id="@+id/action_button"  
     android:selectAllOnFocus="false" 
     android:layout_height="100dip" 
     android:text="Click here to Crop"/> 

</LinearLayout> 
+0

Я просто хочу знать правильный термин, чтобы выровнять что-то выше с чем-то внизу, поэтому я установил верхнюю кнопку, чтобы обнять родительский верх, и я хочу, чтобы кнопка ниже быть прямо под ним с небольшим отступом ... и т. д. – Sapp 2010-11-23 21:34:57

ответ

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

<ImageButton android:layout_below="@+id/Button01" 
      android:id="@+id/ImageButton01"  
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_width="fill_parent"> 
</ImageButton> 
<ImageButton android:layout_below="@+id/ImageButton01" 
      android:id="@+id/ImageButton02" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent"> 
</ImageButton> 
<TextView android:layout_height="wrap_content" 
      android:id="@+id/TextView01" 
      android:text="@+id/TextView01" 
      android:layout_width="wrap_content"  
      android:layout_below="@+id/ImageButton02"> 
</TextView> 
<Button android:text="@+id/Button01" 
      android:id="@+id/Button01" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_width="fill_parent"> 
</Button> 
</RelativeLayout> 

также вас может захотеть посмотреть here и here

1

RelativeLayouts очень легко построить, если вы используете среду IDE, которая поможет вам с параметрами параметров макета.

Что вам нужно, например, андроид: layout_alignParentTop = "истина" и андроид: layout_below = "@ идентификатор/XXXXXXXX"

Эта ссылка поможет вам начать работу: http://developer.android.com/guide/topics/ui/layout-objects.html

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