2011-12-07 3 views
0

Я хочу создать макет, как на изображенииAndroid макет над более linearlayouts

3 зеленых макетов linearlayouts и код показан ниже. Может кто-нибудь дать мне код для других красных макетов над этими тремя зелеными. Какой тип макета должен быть?

enter image description here

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


     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="1"> 

      </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="1"> 

      </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="1"> 

      </LinearLayout> 

</LinearLayout> 

Благодаря

ответ

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" > 

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

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:background="#00ff00" 
      android:layout_marginRight="10dp" > 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:background="#00ff00" 
      android:layout_marginRight="10dp" > 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:background="#00ff00" 
      android:layout_marginRight="10dp" > 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:background="#ff0000" 
      android:orientation="vertical" 
      android:layout_marginTop="200dp" 
      android:layout_marginRight="50dp"> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:background="#ff0000" 
      android:orientation="vertical" 
      android:layout_marginTop="200dp" 
      android:layout_marginRight="50dp"> 
     </LinearLayout> 
    </LinearLayout> 

</RelativeLayout> 
+0

вы экономите мою жизнь! – jlopez

0

RelativeLayout, как правило, используется для перекрытия других макетов. В этом случае вы можете поместить свой LinearLayouts в RelativeLayout, а затем добавить два других макета соответственно в виде дочерних элементов родителя RelativeLayout.

Пример:

<Relativelayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="1"> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="1"> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="1"> 
     </LinearLayout> 
    </LinearLayout> 
    <Linearlayout 
     android:layout_width="200dp" 
     android:layout_height="50dp" 
     android:layout_marginTop="100dp" 
     android:layout_alignParentLeft="true"> 
    </LinearLayout> 
    <Linearlayout 
     android:layout_width="250dp" 
     android:layout_height="50dp" 
     android:layout_marginTop="200dp" 
     android:layout_alignParentLeft="true"> 
    </LinearLayout> 
</RelativeLayout> 

Есть много других атрибутов, которые можно применить к детям, что RelativeLayout будет реагировать, но, что, кажется, не распространяются на то, что вы просили.

0

Вы можете использовать RelativeLayout в верхней части всей иерархии раскладок. Первым расположением в нем будет линейный макет, который будет иметь всю относительную компоновку. Помимо этого, вы можете разместить другие макеты, которые будут размещены далее в относительном макете. Вы можете выровнять их так, как вы хотите, с помощью aligment в соответствии с родителями или друг с другом. удачи

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