目前使用有两种方法:
1、使用新控件NestScrollView 嵌套RecyclerView,使用方法与一般ScrillView嵌套条目一样
xml:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30px"
android:layout_marginRight="30px"
android:layout_marginTop="25px"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title8"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="title8"
android:textSize="@dimen/sp16"/>
<TextView
android:id="@+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title2"
android:textSize="@dimen/sp16"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/testing_activity_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20px"
android:layout_marginRight="20px"
android:visibility="invisible"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
在代码中的调用和一般的RecyclerView的使用是一样的,没有任何改变。但是我用的时候界面滑动出现了卡顿现象,而且没有惯性滑动了。
解决方案:代码中RecyclerView 设置
LinearLayoutManager layoutManager = new LinearLayoutManager(TestingActivity.this);
layoutManager.setSmoothScrollbarEnabled(true);
layoutManager.setAutoMeasureEnabled(true);
test_recycler.setLayoutManager(layoutManager);
test_recycler.setHasFixedSize(true);
test_recycler.setNestedScrollingEnabled(false);
2、使用ScrollView
使用ScrollViedw嵌套RelativeLayout,RelativeLayout里面放RecyclerView。
xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30px"
android:layout_marginRight="30px"
android:layout_marginTop="25px"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.RecyclerView
android:id="@+id/testing_activity_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20px"
android:layout_marginRight="20px"
android:visibility="visible"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
在代码中也是没做处理,感觉可能和我的Pad的Android有关系,使用的Android4.4的pad,不清楚后续会不会出现问题,暂时到这,后续更新。