我一直在寻找这个问题的解决方案,我能找到的唯一答案似乎是" 不要将ListView放入ScrollView ".我还没有看到任何真正的解释为什么.我似乎找到的唯一原因是Google认为你不应该这样做.好吧,我做了,所以我做到了.
所以问题是,如何将ListView放入ScrollView而不将其折叠到最小高度?
我正在为回收者视图寻找相当于addHeaderView的东西.基本上我想要一个带有2个按钮的图像作为标题添加到列表视图中.是否有不同的方法将标题视图添加到回收站视图?指导的一个例子会很有帮助
编辑2(添加片段布局):
添加日志语句后,似乎getViewType只接收到0的位置.这导致onCreateView只加载一个布局:
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序来管理书籍集(如播放列表).
我想显示一个带有垂直RecyclerView的集合列表,并在每行内部显示一个水平RecyclerView中的书籍列表.
当我将内部水平RecyclerView的layout_height设置为300dp时,它会正确显示,但是当我将其设置为wrap_content时,它不会显示任何内容. 我需要使用wrap_content,因为我希望能够以编程方式更改布局管理器以在垂直和水平显示之间切换.

你知道我做错了什么吗?
我的片段布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<com.twibit.ui.view.CustomSwipeToRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/shelf_collection_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"/>
</LinearLayout>
</com.twibit.ui.view.CustomSwipeToRefreshLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
集合元素布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF">
<!-- Simple Header -->
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/empty_collection"
android:id="@+id/empty_collection_tv"
android:visibility="gone"
android:gravity="center"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/collection_book_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <!-- android:layout_height="300dp" -->
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
书目项目:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="180dp"
android:layout_height="220dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/shelf_item_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxWidth="150dp"
android:maxHeight="200dp"
android:src="@drawable/placeholder"
android:contentDescription="@string/cover"
android:adjustViewBounds="true"
android:background="@android:drawable/dialog_holo_light_frame"/> …Run Code Online (Sandbox Code Playgroud) android android-layout android-support-library android-studio android-recyclerview
对于我的应用程序,我使用的是一个RecyclerView内部ScrollView,其RecyclerView高度基于其内容使用此库.滚动工作正在进行,但滚动时滚动不顺畅RecyclerView.当我滚动ScrollView它自己时,它滚动顺畅.
我用来定义的代码RecyclerView:
LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false);
mFriendsListView.setLayoutManager(friendsLayoutManager);
mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null));
Run Code Online (Sandbox Code Playgroud)
该RecyclerView在ScrollView:
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:id="@+id/friendsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud) android android-scrollview android-scroll android-recyclerview
我在RecyclerView里面使用NestedScrollView,它的工作原理.但是当我使用RecyclerView内部LinearLayout或其他东西时,它会根据手势以不同的速度滚动.滚动听手势,如果我只滑了一下,那么滚动一点,如果我快速向上滑动,那么它滚动得非常快.现在我的问题是RecyclerView内部NestedScrollView肯定滚动但快速滚动不起作用.但是我快速或慢速滑动,RecyclerView或NestedScrollView只滚动一点点.
如何使滚动视图中的内部NestedScrollView或RecyclerView内部以各种速度滚动?
我有这样的布局:
<NestedScrollView>
<RecyclerView> // vertical recycler view
<RecyclerView/> // horizontal recycler view
<RecyclerView/>
<RecyclerView/>
...
<RecyclerView>
</NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
我在horizontal Recycler视图中禁用了NestedScrolling :
horizontalRecyclerView.setHasFixedSize(true);
horizontalRecyclerView.setNestedScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud)
在vertical recyclerview不滚动一扔,每当ACTION_UP发生了,vertical recyclerview也停止滚动.
如何在Playstore vertical recyclerview内部nestedscrollview和horizontal recyclerview内部vertical recyclerview嵌套并保持滚动顺畅.
使用@vrund purohit的自定义嵌套滚动视图(下面的代码),并禁用nestedscroll垂直和水平recyclelerview:
verticalRecyclerView.setNestedScrollingEnabled(false);
... add each horizontal recyclerviews:
horizontalRecyclerView.setNestedScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud) 我在ScrollView中有一个回收站视图.我想禁用回收器视图滚动,以便它侦听其父布局,一个ScrollView!
我有一个RecyclerView包裹在一个LinearLayout,它按预期完美地工作.我可以看到RecyclerView填充的所有数据.到现在为止还挺好.
当我裹LinearLayout在ScrollView,在RecyclerView一片空白.我内心没有看到任何东西RecyclerView.为什么?如何使这项工作.
该页面是a中的一个选项卡ViewPagerIndicator,因此该选项卡中的所有内容都必须位于ScrollView.
谢谢你的帮助.
我正在尝试在ScrollView中显示水平Recyclerview项目和垂直Recyclerview项目
即使我使用android:Scrollview也无法正常工作:fillViewport ="true"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Horizontal Recyclerview items
<RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RecyclerView>
//vertical Recyclerview items
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"></RecyclerView>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 随着23.2版本,我们现在可以使用WRAP_CONTENT的recyclerView高度,这是伟大的.我这样做,但是我想在将项目添加(或删除)到适配器后重新计算高度(从而增加或减少高度).
我的特别RecyclerView是从1个项目开始,然后在用户进行选择时添加项目.所以我需要RecyclerView布局来增加高度,直到一点.理想情况下,当列表增加或减少时,平滑动画会发生这种情况.
WRAP_CONTENT布局后如何制作?
尝试:
recyclerview.requestLayout();
recyclerview.invalidate();
Run Code Online (Sandbox Code Playgroud)