选项卡,ListView具有水平和垂直滚动?

时间:2017-10-05 16:23:12

标签: android

我需要在列表中创建一个带有项目(tile)的屏幕(活动/片段),该列表可以水平和垂直滚动+标签。像Google Play上的主页一样。 见截图:

Google play main page

最佳解决方案是什么?也许建议一些好的库/组件。 感谢。

3 个答案:

答案 0 :(得分:1)

这是更好的方法

  1. 创建ScrollView
  2. 使用LinearLayout
  3. 制作CardView
  4. 使用horizontal滚动RecyclerView并为每行制作卡片。
  5. 重复步骤 3 4
  6. 享受。

答案 1 :(得分:0)

您可以按步骤

执行此操作
  1. 创建顶部标签。
  2. 在主页标签中,使用自定义视图创建ListView
  3. 为此列表创建自定义适配器,并使用另一个水平遍历的列表填充列表视图的每一行。
  4. 因此,您将有两个列表,第一个垂直遍历,第二个列表将填充到第一个列表的行中并横向遍历。

    尝试解决此问题,然后在遇到错误时更新此问题。

    希望这会有所帮助:)

答案 2 :(得分:0)

真的很简单。您需要做的就是设置" nestedScrollingEnabled"在父级中标记为true。关于如何使用scrollview作为根布局在xml中执行此操作的一个非常高级的示例:

- ScrollView
 ------ RelativeLayout //作为scrollview只能有一个子
 --------- RecyclerView1 - >将LayoutManager设置为HORIZONTAL
 --------- RecyclerView2 - >将LayoutManager设置为HORIZONTAL
------- EndRelativeLayout
--EndScrollView

这对我有用(你可以忽略@ id / headers部分):

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none">

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/next"
        android:nestedScrollingEnabled="true"
        tools:ignore="MissingPrefix">

        <TextView
            android:id="@+id/header1"
            fontPath="fonts/CircularStd-Bold.otf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="24dp"
            android:text=""
            android:textSize="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/header2"
            fontPath="fonts/CircularStd-Bold.otf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="24dp"
            android:text=""
            android:textSize="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recycler_view_2" />

        <TextView
            android:id="@+id/textView26"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"

            android:layout_marginTop="16dp"
            android:paddingBottom="100dp"
            android:text=""
            android:visibility="gone"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recycler_view_1" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="24dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollbars="none"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/header2" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="24dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollbars="none"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/header1" />

    </android.support.constraint.ConstraintLayout>

</ScrollView>
相关问题