2015-11-03 74 views

回答

0

沒有基本的佈局是我們的方便, 和每個佈局有其獨特的用途。

像...

  1. 用於與重量(可選)線性結構線性佈局
  2. 相對佈局免費設置組件及其相對於彼此以及父母的位置。
  3. 框架佈局免費使用組件和重力位置。
  4. 在電網結構集合組成的網格佈局

對於一些複雜的設計,你可以使用佈局的嵌套結構。

+1

謝謝拉維的好解釋:) – Zain1122

0

所有佈局都有獨特的功能。 取決於風格,哪種佈局適合這種風格。

線性和相對最常用。不同的是... 在相對佈局中,所有的部件都由ID控制。 示例...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<TextView 
    android:text="Hello" 
    android:id="@+id/text1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<Button 
    android:layout_below="@+id/text1" 
    android:text="Done" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 

在LinearLayout中。你有重量。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="2" 
android:orientation="horizontal"> 

<TextView 
    android:layout_weight="1" 
    android:text="Hello" 
    android:id="@+id/text1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<Button 
    android:layout_weight="1" 
    android:layout_below="@+id/text1" 
    android:text="Done" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</LinearLayout> 

在網格佈局中有行和列來調整您的佈局。

請注意.... 一個活動有多個佈局...... :) Cheeers .... !!!!

+0

非常感謝你們,我希望我們都需要在android的世界中學習很多東西:)最好的祝福 – Zain1122