2017-10-05 191 views
0

我需要創建一個屏幕(活動/片段)與列表中的項目(平鋪),可以水平和垂直+標籤滾動。類似於Google Play上的主頁面。 見截圖:帶有水平和垂直滾動的Tabs,ListView?

Google play main page

什麼這個最好的解決辦法是什麼?也許建議一些好的圖書館/組件。 謝謝。

回答

0

可以在步驟

  1. 爲此創建頂級標籤。
  2. 在主頁選項卡中創建一個帶自定義視圖的ListView
  3. 爲此列表創建一個自定義適配器,並使用另一個橫向遍歷的列表填充listview的每一行。

所以你將有兩個列表,第一個垂直遍歷,第二個將填充到第一個列表的行中,並橫向遍歷。

嘗試解決這個問題,然後在遇到錯誤時更新此問題。

希望這有助於:)

+0

Atleast建議'RecyclerView'而不是'ListView' – Dennis

1

這裏是更好的辦法

  1. 創建ScrollView
  2. 使用LinearLayout
  3. 做一個CardView
  4. 將一個RecyclerViewhorizontal滾動和補卡對於每一行..
  5. 重複步驟和。

享受。

0

真的很簡單。你需要做的就是在父代中設置「nestedScrollingEnabled」標誌爲true。如何你可以用滾動視圖做它在XML作爲根佈局非常高的水平例子:

--ScrollView
------ RelativeLayout的//爲滾動視圖只能有一個孩子
--- ------ RecyclerView1 - >設置佈局管理水平來
--------- RecyclerView2 - >設置佈局管理到水平
------- EndRelativeLayout
--EndScrollView

這適用於我(您可以忽略@ id /頭部分):

<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>