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。“这应该会奏效的。”卡希尔确实做到了。谢谢如果你想发表你的评论作为回答,我可以接受。