Android 当宽度设置为匹配父项时,GridLayout第二列内的LinearLayout溢出屏幕
我正在尝试将Android 当宽度设置为匹配父项时,GridLayout第二列内的LinearLayout溢出屏幕,android,android-layout,layout,android-linearlayout,android-gridlayout,Android,Android Layout,Layout,Android Linearlayout,Android Gridlayout,我正在尝试将LinearLayout放置在父级GridLayout的第二列中。我希望在第一列中放置textView,在第二列中放置线性布局 问题是,当我将LinearLayout's with属性设置为match\u parent时,线性布局会以大于列中剩余空间的宽度展开,并且GridLayout会溢出屏幕,如下图所示 我假设LinearLayout的父项不是GridLayout的第二列,因此match\u parent键将宽度设置为整个屏幕的宽度(也适用于具有match\u parent属性的
LinearLayout
放置在父级GridLayout
的第二列中。我希望在第一列中放置textView
,在第二列中放置线性布局
问题是,当我将LinearLayout
's with属性设置为match\u parent
时,线性布局会以大于列中剩余空间的宽度展开,并且GridLayout
会溢出屏幕,如下图所示
我假设LinearLayout
的父项不是GridLayout的第二列,因此match\u parent键将宽度设置为整个屏幕的宽度(也适用于具有match\u parent属性的高度)
我正在寻找一种方法,使列成为线性布局
的父项,从而填充文本视图
我想故意使用网格布局,因为它在设计上有优势。我也是android新手,所以任何帮助都会很感激
以下是布局代码,以防万一:
<GridLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:columnCount="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView3" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView4" />
</GridLayout>
好的,问题是我试图用android:layout\u width填充剩余的水平空间,并将其设置为
match\u parent
。这种方法的问题是,使用match parent,我将布局的宽度设置为其父级(网格布局)的宽度,该宽度与整个屏幕一样大,因此,它会溢出设备屏幕
为了实现我的目标,我应该将android:layout\u gravity设置为fill\u horizontal