1

私はRecyclerViewを水平に、gridviewを垂直にスクロールさせたレイアウトをしています。 しかし、リサイクルビューではスクロールアップが行われず、グリッドビューは水平リサイクルビューリストの下に垂直にスクロールされます。アンドロイドのレイアウトは、gridviewとRecyclerViewでスクロール

レイアウト全体を垂直にスクロールしながら、recyclerviewを水平方向にスクロールします。あなたはリサイクルビューでGridViewコントロールを使用している理由

content_main.xml

<LinearLayout 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="wrap_content" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.test.MainActivity" 
tools:showIn="@layout/app_bar_dash_board" 
android:orientation="vertical" 
android:scrollbars="vertical"> 
     <android.support.v7.widget.RecyclerView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentTop="true" 
      android:orientation="horizontal" 
      android:scrollbars="none" /> 
     <GridView 
      android:id="@+id/gridView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:verticalSpacing="0dp" 
      android:horizontalSpacing="0dp" 
      android:stretchMode="columnWidth" 
      android:scrollbars="none" 
      android:numColumns="2" 
      /> 
</LinearLayout> 

grid_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ImageView 
    android:id="@+id/grid_item_image" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop"/> 
<TextView 
    android:id="@+id/grid_item_title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:paddingTop="15dp" 
    android:paddingBottom="15dp" 
    android:layout_gravity="bottom" 
    android:textAlignment="center" 
    android:textColor="@android:color/white" 
    android:background="#55000000"/> 
</FrameLayout> 

答えて

1

。正しく動作しません。グリッドビューが必要な場合は、recyclerviewをグリッドビューとして使用できます。 リサイクラーのビューレイアウトマネージャーをStaggeredGridLayoutManagerとして設定します。好きなように使ってください。

recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL)); 

あなたの主なレイアウトは、スクロールビューでなければなりませんし、あなたのリサイクルビューの高さは、親と一致してはならないhttps://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html

0

からrefreanceを取ります。

子供の数に基づいてグリッドビューの高さを動的に設定する必要があります。

関連する問題