3

Iam试图在NestedScrollView中放置一个RecyclerView。问题是,如果我把RecyclerView放在一个水平的LinearLayout中,回收站视图就会显示出来。但是,如果我将它放到垂直LinearLayout中,它不会显示出来。这是我曾尝试过的东西:RecyclerView inside NestedScrollView Android

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginBottom="32dp" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 
      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="80dp"> 
       <android.support.v7.widget.Toolbar 
        android:id="@+id/anim_toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="20dp" 
        android:background="@color/AppBrightRed" 
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
       <ImageView 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:src="@drawable/ic_appicon" 
        android:layout_marginLeft="10dp" 
        android:layout_gravity="bottom|left" /> 
      </FrameLayout> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
     <LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:orientation="vertical"> 
      <fragment 
       android:id="@+id/map" 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:name="com.google.android.gms.maps.MapFragment" 
       app:layout_collapseMode="parallax" /> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerView" 
       android:scrollbars="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     <LinearLayout 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp"> 
       <AutoCompleteTextView 
        android:layout_height="wrap_content" 
        android:layout_width="180dp" 
        android:hint="LOCATION" 
        android:id="@+id/ATView" /> 
       <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="Checkin" 
        android:textColor="@color/AppBackground" 
        android:id="@+id/btnCheckin" 
        android:background="@color/AppBrightRed" /> 
       <android.support.v7.widget.RecyclerView ----DOES NOT SHOW IF PLACED HERE 
      android:id="@+id/recyclerView" 
      android:scrollbars="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
       </LinearLayout> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 
</android.support.design.widget.CoordinatorLayout> 

我该如何解决这个问题?

+0

变化'layout_height' recyclerview的母公司线性布局,以'match_parent' – Apurva

+0

@Apurva感谢您的答复。但是这也行不通 –

+2

[如何在NestedScrollView中使用RecyclerView?](http://stackoverflow.com/questions/31000081/how-to-use-recyclerview-inside-nestedscrollview) – DmitryArc

回答

4

可以使用LinearLayout代替NestedScrollView

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:orientation="vertical"> 

     <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" 
     /> 

    </LinearLayout> 
+0

呵呵。这工作。我使用了一个'FrameLayout'而不是'LinearLayout',它也*工作!请注意,我在'RecyclerView'上以编程方式调用'setNestedScrollingEnabled(true)'。奇怪的是,我并不认为折叠/滚动仍然可以,但它确实!谢谢你的提示。 –

0

你可以看看:How to use RecyclerView inside NestedScrollView?

顺便说一句,它不会工作,我用尽了一切,你甚至可以把它想象。

但是,你有以下选择:

使用图书馆像 https://github.com/serso/android-linear-layout-manager

2.或者,实现自己的自定义LinearLayoutManager

或使用app:layout_behavior="@string/appbar_scrolling_view_behavior" 都可以(可能会有效)

而coure,你可以使用CoordinatorLayoutNestedScrollView之外。

检查这个答案:https://stackoverflow.com/a/34951558/4409113

相关问题