【发布时间】:2014-07-17 02:20:39
【问题描述】:
我有一个ListView,我想将它显示在GridView 的左侧。我使用以下 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>
有问题的是,只有ListView 在活动启动时出现。我意识到这很简单,但是我很久没有编码了,并且无法使用 Google 找到有用的信息。
谢谢!
【问题讨论】:
-
你在 ListView 和 GridView 上都使用了 android:layout_width="match_parent" 这就是为什么 ListView 首先占据了父视图的所有宽度,即相对布局。尝试使用具有水平方向的 LinearLayout 并将 weightSum 设置为 2,然后将 GridView 和 ListView 的权重设置为 1,将 layout_width 设置为 0dp。这应该可以解决问题。
-
@KaHeL 确实做到了。谢谢!如果您想发表您的评论作为我可以接受的答案。
标签: android listview gridview layout