2012-05-24 98 views
-1

我有下一個XML代碼機器人佈局固定尺寸

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight=".10"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#aa0000" 
      android:text="top"/>  

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight=".70"> 

     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="#00aa00"> 
      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
       <TextView 

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:textSize="50pt" 
        android:text="center"> 
       </TextView> 
       <TextView 

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:textSize="50pt" 
        android:text="center"> 
       </TextView> 
       <TextView 

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:textSize="50pt" 
        android:text="center"> 
       </TextView> 
       <TextView 

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:textSize="50pt" 
        android:text="center"> 
       </TextView> 
       <TextView 

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:textSize="50pt" 
        android:text="center"> 
       </TextView> 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout>  
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@android:color/white" 
     android:layout_weight=".20"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#0000aa" 
      android:text="bottom"/> 
     </LinearLayout>   


</LinearLayout> 

在主的LinearLayout我有三個的LinearLayout。對於第一個LinearLayout,我需要設置100px。對於第三個LinearLayout,我需要設置200px。第二個LinearLayout的所有其他大小。

+0

你似乎沒有問題。如何簡單地設置所需的尺寸? (如果您不知道使用哪些標籤,請查看文檔) – keyser

回答

1

在Android中不推薦使用固定尺寸,因爲它可能會以不同的屏幕分辨率破壞您的佈局。您應該使用android:layout_weight來定義這種類型的屏幕比例。最後,不要使用px來定義佈局大小,而使用pt來分別使用dp和sp。