【发布时间】:2017-10-05 13:00:46
【问题描述】:
我有这样的回收站视图:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
还有这样的物品:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="100dp"
android:layout_height="70dp"
android:scaleType="fitCenter"
android:layout_margin="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:linksClickable="true" />
</LinearLayout>
我在代码中这样做是为了有一个包含 2 列的网格:
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2, LinearLayoutManager.VERTICAL,false);
_recycler.setLayoutManager(gridLayoutManager);
我希望每个项目都占用可用的“match_parent”空间,但事实并非如此!每个项目占用可用空间的一半。如何让 item 具有 width="match_parent" 和水平滚动的可能性?
我想要这样的东西:
screen
|------|
ITEM1 - ITEM2
ITEM3 - ITEM4
【问题讨论】:
-
你想要水平和垂直滚动?
-
nop,因为我想在没有垂直滚动的情况下显示所有内容。我只想提供水平滚动来显示“隐藏”的项目。 (因为如果每个项目都显示在匹配父项中,则必须滚动才能看到其他项目)
-
所以你想一次显示一个项目?并水平滚动?
-
不,我们可以看到很少的项目。每个项目都必须采用“宽度”中的所有可用项目,所以我可以在视图上有 3、4、5 个项目,我不知道,这取决于每个视图的高度。我想水平滚动以显示第 2 列中包含的项目。(这是隐藏的,因为第 1 列的项目获得了视图屏幕中可用的所有宽度)
标签: android android-recyclerview gridlayoutmanager