我正在尝试在另一个带有 Horizontal LinearLayoutManager 的 RecyclerView 中使用带有 Horizontal LinearLayoutManager 的 RecyclerView。整个层次结构是这样的:RecyclerView,Recycler 的子元素是一个 ScrollView,它包含一个 TextView 和另一个 RecyclerView。为了更好地理解,我希望第一个回收器的工作方式类似于但不完全相同的 ViewPager(我不想使用 ViewPager)。问题是当我尝试在子回收器上水平滚动时,运动事件被父回收器捕获,导致滚动到下一页而无法滚动子回收器。
主活动布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/RVpage"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="false"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
主活动.java:
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRecycler();
}
private void setRecycler() {
recyclerView=(RecyclerView) findViewById(R.id.RVpage);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
BigRecyclerAdapter bigRecyclerAdapter=new BigRecyclerAdapter(this);
recyclerView.setAdapter(bigRecyclerAdapter);
//recyclerView.setNestedScrollingEnabled(true);
recyclerView.setLayoutManager(new LinearLayoutManager(
this, LinearLayoutManager.HORIZONTAL, false)
);
}
}
慕斯王
慕田峪7331174
相关分类