如何在 Tabbed Activity - Android 中使用 scrollView?
How to use scrollView in Tabbed Activity - Android?
有谁知道如何在 fragment
中使用 ScrollView
在创建新的 activity
时使用 Tabbed Activity Template
。它默认使用 viewPager
,我制作了 3 个选项卡,其中包含 3 种不同的布局,我可以在其中滑动。但是每次我尝试在这些选项卡中的任何一个中使用 ScrollView
时,程序都会出现错误并且什么也没有发生,有时我什至无法滑动。所以,换句话说:
我的问题:当使用默认的 tabbed activity template
和 ViewPager
时,在 tab(fragment)
中使用 scrollview
的正确方法是什么?
更新 1
NestedScrollView
的事情奏效了,但现在这是伴随解决方案而来的新问题。 AppBar 与其他内容一起滚动。我该如何解决这个问题?
更新 2
看起来 scrollView
对这种类型的 AppBar
有影响(更具体地说是工具栏),我只是通过将 app:layout_scrollFlags="enterAlwaysCollapsed"
添加到 [=] 来解决这个问题26=],它现在是静止的。
补充link:
出于我们大多数人可能不太清楚的原因,当您想滚动与滑动时,很难区分触摸事件。
为了解决这个问题,我使用了 NestedScrollView 而不是常规的 ScrollView。
另一种选择是捕获事件并覆盖它们 - 显然更复杂但可行。
你可以看看我最近在 github 上的代码作为例子。
祝你好运,请告诉我它是否适合你!
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
your content here.........
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
有谁知道如何在 fragment
中使用 ScrollView
在创建新的 activity
时使用 Tabbed Activity Template
。它默认使用 viewPager
,我制作了 3 个选项卡,其中包含 3 种不同的布局,我可以在其中滑动。但是每次我尝试在这些选项卡中的任何一个中使用 ScrollView
时,程序都会出现错误并且什么也没有发生,有时我什至无法滑动。所以,换句话说:
我的问题:当使用默认的 tabbed activity template
和 ViewPager
时,在 tab(fragment)
中使用 scrollview
的正确方法是什么?
更新 1
NestedScrollView
的事情奏效了,但现在这是伴随解决方案而来的新问题。 AppBar 与其他内容一起滚动。我该如何解决这个问题?
更新 2
看起来 scrollView
对这种类型的 AppBar
有影响(更具体地说是工具栏),我只是通过将 app:layout_scrollFlags="enterAlwaysCollapsed"
添加到 [=] 来解决这个问题26=],它现在是静止的。
补充link:
出于我们大多数人可能不太清楚的原因,当您想滚动与滑动时,很难区分触摸事件。
为了解决这个问题,我使用了 NestedScrollView 而不是常规的 ScrollView。
另一种选择是捕获事件并覆盖它们 - 显然更复杂但可行。
你可以看看我最近在 github 上的代码作为例子。
祝你好运,请告诉我它是否适合你!
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
your content here.........
</LinearLayout>
</android.support.v4.widget.NestedScrollView>