Android 如何在GridView旁边获得ListView
我有一个Android 如何在GridView旁边获得ListView,android,listview,gridview,layout,Android,Listview,Gridview,Layout,我有一个列表视图,我想显示在网格视图的左侧。我使用以下xml代码试图实现这一点: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orie
列表视图
,我想显示在网格视图的左侧。我使用以下xml代码试图实现这一点:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView_items">
</ListView>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridView_board"
android:layout_toRightOf="@id/listView_items">
</GridView>
</RelativeLayout>
有问题的是,在启动活动时,只有列表视图
。我意识到这很简单,但我已经很久没有编写代码了,也无法使用谷歌找到有用的信息
谢谢 您在列表视图
和网格视图
上都使用了android:layout\u width=“match\u parent”
,这就是为什么列表视图
首先占据父视图的所有宽度,即相对视图
将RelativeLayout
更改为具有水平方向的LinearLayout
,并将weightSum
设置为2,然后将GridView
和ListView
的权重设置为1,布局宽度设置为0dp
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2" >
<ListView
android:id="@+id/listView_items"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<GridView
android:id="@+id/gridView_board"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</GridView>
</LinearLayout>
您在ListView和GridView上都使用了android:layout\u width=“match\u parent”,这就是为什么ListView首先占据了parentview的所有宽度,parentview是相对视图。尝试使用水平方向的线性布局,将权重和设置为2,然后将GridView和ListView的权重设置为1,将布局宽度设置为0dp。“这应该会奏效的。”卡希尔确实做到了。谢谢如果你想发表你的评论作为回答,我可以接受。