1

我有布局与RecyclerView垂直滚动水平和gridview。 但recyclerview不会在活动中向上滚动,使gridview垂直滚动到水平recyclerview列表下方。android布局与gridview和RecyclerView滚动

我希望recyclerview水平滚动,而整个布局垂直滚动。

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

为什么您使用的是回收视图GridView控件。它不会表现正确。如果你想要一个网格视图,你可以使用recyclerview作为网格视图。 将您的回收视图布局管理器设置为StaggeredGridLayoutManager。像使用它。

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

采取从https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html

0

你的主要布局的refreance应该是滚动视图和你的看法回收高度应不匹配父。

您需要根据子元素的数量动态设置网格视图的高度。