所以我在垂直ScrollView里面有一个水平的ScrollView。我的布局中的所有东西都显示得很好,所有的卷轴都在我想要的方向上滚动,而且它做得很顺利。
我唯一的问题是,RecyclerView在ScrollView中的其他内容下面,当RecyclerView部分可见时,它将在RecyclerView底部与启动时的屏幕底部连线。这意味着RecyclerView上方的内容将从屏幕上推开。
有人知道为什么会发生这种事吗?我怎么才能解决呢?
下面是我刚才描述的一个简单的布局。您甚至不需要填充RecyclerView,它仍然会这样做。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#fff"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#000"/>
</LinearLayout>
</ScrollView>发布于 2015-09-07 12:28:30
原来这个问题是向谷歌这里报告的,第81854期
据谷歌( Google )称,它正在按预期运作。问题在于RecyclerView将focusableInTouchMode设置为true。为了解决这个问题,我将focusableInTouchMode和focusable设置为ScrollView的最顶层视图中的true。
下面是我在原始问题中提供的代码示例的修复:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#fff"
android:focusableInTouchMode="true"
android:focusable="true"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#000"/>
</LinearLayout>
</ScrollView>发布于 2022-03-30 12:21:52
很长时间以来,我一直在寻找解决方案。最后,我偶然做出了决定。在您的活动中,找到ScrollView并为其添加一个触摸监听器。一切都会正常运转的
ScrollView scroll = findViewById(R.id.scroll);
scroll.setOnTouchListener((view, motionEvent) -> {
return false;
});https://stackoverflow.com/questions/32394115
复制相似问题