2013-03-19 175 views
0
不擴大

我有我的佈局下面的代碼:按鈕在安卓

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/background_color" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" > 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true"> 

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

      <TextView 
       android:id="@+id/textView0" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="left|center_vertical" 
       android:text="" 
       android:textColor="@color/text_color" 
       android:textSize="@dimen/nav_text_size" > 
      </TextView> 

      <Button 
       android:id="@+id/ProceedToScreen31" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:drawableRight="@drawable/ic_action_name" 
       android:gravity="left|center_vertical" 
       android:text="@string/TA1" 
       android:textColor="@color/btn_text_color" 
       android:textSize="@dimen/button_text_size" > 
      </Button> 

      <Button 
       android:id="@+id/ProceedToScreen32" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:drawableRight="@drawable/ic_action_name" 
       android:gravity="left|center_vertical" 
       android:text="@string/TA2" 
       android:textColor="@color/btn_text_color" 
       android:textSize="@dimen/button_text_size" > 
      </Button> 

      <Button 
       android:id="@+id/ProceedToScreen33" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:drawableRight="@drawable/ic_action_name" 
       android:gravity="left|center_vertical" 
       android:text="@string/TA3" 
       android:textColor="@color/btn_text_color" 
       android:textSize="@dimen/button_text_size" > 
      </Button> 

      <Button 
       android:id="@+id/ProceedToScreen34" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:drawableRight="@drawable/ic_action_name" 
       android:gravity="left|center_vertical" 
       android:text="@string/TA4" 
       android:textColor="@color/btn_text_color" 
       android:textSize="@dimen/button_text_size" > 
      </Button> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="2dip" 
       android:background="@color/line_color" > 
      </View> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/copyright" 
       android:textColor="@color/text_color" 
       android:textSize="@dimen/small_text_size" > 
      </TextView> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

這樣做的問題是,當我把我的電話景觀,按鈕不擴展和填充只有一半屏幕。

如何讓我的按鈕展開以填充屏幕的其餘部分?

+0

你可以發佈截圖嗎? – dannyroa 2013-03-19 18:51:26

+0

「嘗試了很多選擇」,你試過了什麼? – 2013-03-19 18:56:57

回答

1

你的按鈕是好的,但他們的父母(線性佈局)不像屏幕那麼大,因爲它的寬度設置爲wrap_content。只需更改爲match_parent即可。

match_parent =設置尺寸以匹配父元素的尺寸。在API級別8中添加以反對fill_parent。

希望這有助於

0

怎麼樣讓你的LinearLayout寬度設置爲match_parent

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/background_color" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" > 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/textView0" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left|center_vertical" 
      android:text="" 
      android:textColor="@color/text_color" 
      android:textSize="@dimen/nav_text_size" > 
     </TextView> 

     <Button 
      android:id="@+id/ProceedToScreen31" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableRight="@drawable/ic_action_name" 
      android:gravity="left|center_vertical" 
      android:text="@string/TA1" 
      android:textColor="@color/btn_text_color" 
      android:textSize="@dimen/button_text_size" > 
     </Button> 

     <Button 
      android:id="@+id/ProceedToScreen32" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableRight="@drawable/ic_action_name" 
      android:gravity="left|center_vertical" 
      android:text="@string/TA2" 
      android:textColor="@color/btn_text_color" 
      android:textSize="@dimen/button_text_size" > 
     </Button> 

     <Button 
      android:id="@+id/ProceedToScreen33" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableRight="@drawable/ic_action_name" 
      android:gravity="left|center_vertical" 
      android:text="@string/TA3" 
      android:textColor="@color/btn_text_color" 
      android:textSize="@dimen/button_text_size" > 
     </Button> 

     <Button 
      android:id="@+id/ProceedToScreen34" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableRight="@drawable/ic_action_name" 
      android:gravity="left|center_vertical" 
      android:text="@string/TA4" 
      android:textColor="@color/btn_text_color" 
      android:textSize="@dimen/button_text_size" > 
     </Button> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dip" 
      android:background="@color/line_color" > 
     </View> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/copyright" 
      android:textColor="@color/text_color" 
      android:textSize="@dimen/small_text_size" > 
     </TextView> 
    </LinearLayout> 
</ScrollView> 

0

設置的Android佈局寬度,以填補父爲:

android:layout_width="fill_parent" 

記得,whetever你想以適應屏幕寬度完全,將其佈局寬度設置爲fill_parent

+1

'fill_parent'已棄用。你應該使用'match_parent'來代替 – TronicZomB 2013-03-19 19:05:01

+0

,將「Linear Layout」的layout_width設置爲fill_parent ..好吧, – 2013-03-19 19:07:11

+0

即使在LinearLayout上,你仍應該使用'match_parent'。 – TronicZomB 2013-03-19 19:08:24

0

創建一個名爲佈局,土地文件夾現在,創建其中U已經肖像創建佈局的名稱相同的佈局,在風景模式下,每個組件相同的ID。由於您正在使用它,文件夾「layout-land」屏幕將處於橫向模式。根據您的要求設計佈局。現在,當你改變顯示模式時,android會在顯示模式之間切換。謝謝 。玩得開心