Kul*_*Ken 11 android scroll android-recyclerview
我正在制作一个应用程序,以1视图显示所有产品.我希望recyclerview显示所有项目并且无法滚动,只需滚动父视图(ScrollView).但问题是不能使回收者的高度包裹所有内容.
这是我的代码:
<TextView
android:text="Best seller:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView4"
android:textColor="#3f3f3f"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="horizontal"
android:id="@+id/rv_bestSeller"
android:layout_height="200dp" />
<TextView
android:text="New Product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:textSize="18sp"
android:textColor="#3f3f3f" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="horizontal"
android:layout_height="200dp"
android:id="@+id/rv_newProduct"/>
<TextView
android:text="All Product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView6"
android:textSize="18sp"
android:textColor="#3f3f3f" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rv_allProduct" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
yan*_*win 11
这样做是不好的做法,如果你这样做是因为标题使用了这个库 https://github.com/emilsjolander/StickyListHeaders
它会给你标题,你不需要里面有列表的滚动视图.
如果你真的想以这种方式继续使用NestedScrollView而不是常规的Scrollview
https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html
这将允许你像你想要的那样禁用嵌套滚动
Sar*_*ara 10
你应该使用NestedScrollView和setNestedScrollingEnabled(false)组合.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7957 次 |
| 最近记录: |