如何在NestedScrollView中显示滚动条
问题描述:
嘿,我在Activity中实现了NestedScrollView,但是我不能像在ScrollView中一样显示滚动条,
Hey i implemented a NestedScrollView in an Activity, but i cant show the scrollbar like i do in a ScrollView, can you guys.
我怎么显示它?
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingLeft="@dimen/dimen_2"
android:paddingRight="@dimen/dimen_2">
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
答
我找到了解决方案,首先将NestedScrollView行为设置为"@ string/appbar_scrolling_view_behavior",然后,我创建了一种样式,以在所有需要的NestedScrollViews中显示滚动条它.
I found the solution, first set the NestedScrollView behaviour to "@string/appbar_scrolling_view_behavior" then, I created a style to show the scrollbars in all NestedScrollViews where I need it.
在styles.xml
中:
<resources>
<!-- other styles -->
<style name="NestedScrollBarStyle">
<item name="android:scrollbarFadeDuration">2</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fillViewport">true</item>
<item name="android:orientation">vertical</item>
</style>
</resources>
在布局中:
<android.support.v4.widget.NestedScrollView
style="@style/NestedScrollBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appBar"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingLeft="@dimen/dimen_2"
android:paddingRight="@dimen/dimen_2">
</LinearLayout>
</android.support.v4.widget.NestedScrollView>