2013-03-19 128 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会在显示模式之间切换。谢谢 。玩得开心