【问题标题】:RecyclerView GridLayoutManager item match_parent widthRecyclerView GridLayoutManager 项目 match_parent 宽度
【发布时间】: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


【解决方案1】:

您不能水平匹配父级并使其水平滚动,您必须切换其中一个。要实现您想要的,您必须使用 FiewFlipper 或选项卡之类的东西。

【讨论】:

  • 我不明白为什么!表格布局可以显示匹配°_parent 的项目并水平滚动。我想使用回收器视图而不是我的表格布局来提高性能,但是......如果不可能:(
  • 你说你不需要垂直滚动,这意味着你的网格中只会有几个项目?如果这样,RecyclerView 不会提高性能,那么只有当您的列表大于任何时候都可以在屏幕上显示时,它才会有所帮助。
  • 不,我不想允许垂直滚动,我要显示所有内容,因为这是一个特定情况,所以是的,我认为 Recyclerview 会提高性能:(
猜你喜欢
  • 2016-06-24
  • 1970-01-01
  • 2021-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-21
相关资源
最近更新 更多