NestedScrollView Android中的RecyclerView
我正在尝试在NestedScrollView中放置RecyclerView。问题是,如果我将RecyclerView放置在水平线性布局中,则会显示recycler视图。但如果我把它放在垂直直线上,它就不会显示。以下是我尝试过的一些东西:NestedScrollView Android中的RecyclerView,android,android-recyclerview,android-design-library,nestedscrollview,Android,Android Recyclerview,Android Design Library,Nestedscrollview,我正在尝试在NestedScrollView中放置RecyclerView。问题是,如果我将RecyclerView放置在水平线性布局中,则会显示recycler视图。但如果我把它放在垂直直线上,它就不会显示。以下是我尝试过的一些东西: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.andr
<?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>
如何解决此问题?您可以使用
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>
您可以看看: 顺便说一句,这行不通,我已经尝试了你能想象得到的一切 但是,您有以下选择: 1.使用类似 2.或者,实现您自己的自定义
LinearLayoutManager
3.或使用app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
这两种方法都适用。(也许会奏效)
当然,您可以在协调布局
内部和嵌套滚动视图
外部使用它
检查此答案:将recyclerview父级线性布局的
布局高度更改为匹配父级
@Apurva感谢您的回复。但这不起作用。请避免在滚动视图中使用recyclerView。若你们想让它以某种方式工作,它仍然是未来和应用程序滚动性能的问题。Android强烈摒弃了这种设计。这很有效。我使用了FrameLayout
而不是LinearLayout
,它也起作用了!请注意,我通过编程方式在RecyclerView
上调用setNestedScrollingEnabled(true)
。奇怪,我不认为折叠/滚动仍然有效,但它确实有效!!谢谢你的提示。