Android ListView宽度不小于';与父母不匹配
我的android应用程序标记有问题。我在GridLayout内的ListView中将宽度设置为Android ListView宽度不小于';与父母不匹配,android,android-listview,android-gridlayout,Android,Android Listview,Android Gridlayout,我的android应用程序标记有问题。我在GridLayout内的ListView中将宽度设置为match\u parent,并认为它将获得屏幕大小。但在我的实现中,listView的宽度和整个屏幕的大小相匹配,因为左边的列不适合屏幕 我试过使用TableLayout?但结果是一样的:ListView的宽度比我想要的要大,并且超出了屏幕 我应该更改什么来设置ListView宽度以适应屏幕大小。 下面是我的简化标记。 curren结果图片:(这是我的第一个问题,没有足够的声誉在问题中添加图片) 这
match\u parent
,并认为它将获得屏幕大小。但在我的实现中,listView的宽度和整个屏幕的大小相匹配,因为左边的列不适合屏幕
我试过使用TableLayout?但结果是一样的:ListView的宽度比我想要的要大,并且超出了屏幕
我应该更改什么来设置ListView宽度以适应屏幕大小。
下面是我的简化标记。
curren结果图片:(这是我的第一个问题,没有足够的声誉在问题中添加图片)
这是您想要构建的布局,借助于水平方向的线性布局,并使用其android:weightSum属性:
<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:orientation="horizontal"
android:weightSum="100">
<Button
android:id="@+id/selectPhoto"
android:layout_width="185dp"
android:layout_height="70dp"
android:text="Select Image"
android:layout_weight="55"/>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#C8C8C8"
android:divider="#b5b5b5"
android:layout_weight="45" />
</LinearLayout>
我希望这解决了你的问题?是的,它很有效!非常感谢。但我也对如何使用GridLayout感兴趣,因为将有很多按钮,并且左栏和右栏中的一些文本将跨越行。尝试将ListView嵌套在FrameLayout中
<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:orientation="horizontal"
android:weightSum="100">
<Button
android:id="@+id/selectPhoto"
android:layout_width="185dp"
android:layout_height="70dp"
android:text="Select Image"
android:layout_weight="55"/>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#C8C8C8"
android:divider="#b5b5b5"
android:layout_weight="45" />
</LinearLayout>