2013-10-08 181 views
0

我activity_main.xml中看起來像這樣減小尺寸

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TableLayout 
     android:layout_marginTop="40dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"> 
     <TableRow> 
      <EditText 
       android:id="@+id/UsernameText" 
       android:width="250dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dip" 
       android:hint="@string/UsernameText"/> 
     </TableRow> 
     <TableRow> 
      <EditText 
       android:id="@+id/PasswordText" 
       android:width="250dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dip" 
       android:hint="@string/PasswordText" 
       android:inputType="textPassword" /> 
     </TableRow> 
    </TableLayout> 
    <LinearLayout 
     android:layout_marginTop="50dip" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="3" 
     android:gravity="center"> 
     <Button 
      android:id="@+id/MyButton" 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="@string/button" /> 
    </LinearLayout> 
</LinearLayout> 

線性視圖:

enter image description here

水平視圖: enter image description here

如何使按鈕尺寸較小?另外我如何使兩個視圖大致相似?

回答

2

總是建議擁有不同的佈局以支持兩種方向。資源文件夾layout-port和layout-land下有兩個不同的xml佈局文件。你可以閱讀這個頁面,以便更好地理解它是如何完成的。 Multiple screens support

0
// try this 
<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:gravity="center" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:layout_height="match_parent"> 

      <EditText 
        android:id="@+id/UsernameText" 
        android:width="250dp" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dip" 
        android:hint="@string/UsernameText"/> 

      <EditText 
        android:id="@+id/PasswordText" 
        android:width="250dp" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dip" 
        android:layout_marginTop="5dp" 
        android:hint="@string/PasswordText" 
        android:inputType="textPassword" /> 


     <Button 
       android:id="@+id/MyButton" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:text="@string/button" /> 
</LinearLayout> 
+0

這完全填滿屏幕時在水平模式 – misguided

+0

變化父佈局機器人:layout_height =「WRAP_CONTENT」 –