【发布时间】:2022-01-24 15:14:30
【问题描述】:
我的 NestedScrollView 中有两个视图,一个是我单独的 imageview,第二个是显示图像列表的 recyclerview。现在问题是 recyclerview 图像滚动,但我单独的 imageview 保持在它的位置。我希望我的单独 imageview 沿着 recyclerview 图像滚动。
我已经尝试过许多解决方案,例如用户建议使用 setNestedScrollingEnabled(False) 属性的一些 stackoverflow 帖子,但它不起作用。我为此工作了很多天,但没有解决方案有效。如果有人帮助我,我会很高兴!
我的 XML 文件:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView6"
android:layout_width="120dp"
android:layout_height="120dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/sadboy" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/postRV"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView6"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
我的 JAVA 文件:
postRV = findViewById(R.id.postRV);
list = new ArrayList<>();
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
list.add(new StoryModel(R.drawable.girl));
StoryAdapter storyAdapter = new StoryAdapter(getApplicationContext(),list);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.HORIZONTAL,false);
postRV.setLayoutManager(layoutManager);
postRV.setNestedScrollingEnabled(false);
postRV.setAdapter(storyAdapter);
【问题讨论】:
标签: android android-layout android-recyclerview