Android中的按钮未扩展
我的布局有以下代码:Android中的按钮未扩展,android,button,android-orientation,Android,Button,Android Orientation,我的布局有以下代码: <?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="
<?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>
问题是,当我把手机调到横向时,按钮不会展开,只占屏幕的一半
如何使按钮展开以填充屏幕的其余部分?如何将
线性布局的宽度设置为匹配\u父项
<?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>
将android布局宽度设置为填充父级:
android:layout_width="fill_parent"
请记住,无论何时您想要完全适应屏幕宽度,请将其布局宽度设置为“填充父项”您的按钮都可以,但它们的父项(线性布局)没有屏幕大,因为其宽度设置为“环绕内容”。只要更改为匹配您的家长,您就可以了
match_parent=将维度设置为与父元素的维度匹配。在API级别8中添加,以反对填充父项
希望这有助于创建一个名为layout land的文件夹,现在创建一个与您为纵向创建的布局同名的布局,在横向模式下每个组件的id相同。由于您正在使用文件夹“layout land”,您的屏幕将处于横向模式。根据您的要求设计布局。现在,当你改变显示模式时,android将在显示模式之间切换。非常感谢。玩得开心你能发布屏幕截图吗?“尝试了许多选项”,你尝试了什么?fill\u parent
不推荐使用。您应该使用match\u parent
而不是将“Linear layout”的布局宽度设置为fill\u parent。。好的,即使在LinearLayout
上,您仍然应该使用match\u parent
。