如何在 NestedScrollView 中显示滚动条
How to show the Scrollbar in a NestedScrollView
嘿,我在 Activity 中实现了 NestedScrollView,但是我无法像在 ScrollView 中那样显示滚动条,你们可以吗?
如何展示?
<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”,然后,我创建了一个样式来在我需要的所有 NestedScrollView 中显示滚动条。
在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>
使用 android:scrollbars 属性。
如:
android:scrollbars="vertical"
android:scrollbars="horizontal"
android:scrollbars="vertical|horizontal"
例如:
<android.support.v4.widget.NestedScrollView
android:id="@+id/foo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v4.widget.NestedScrollView>
文档 link:https://developer.android.com/reference/android/view/View.html#attr_android:scrollbars
嘿,我在 Activity 中实现了 NestedScrollView,但是我无法像在 ScrollView 中那样显示滚动条,你们可以吗?
如何展示?
<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”,然后,我创建了一个样式来在我需要的所有 NestedScrollView 中显示滚动条。
在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>
使用 android:scrollbars 属性。
如:
android:scrollbars="vertical"
android:scrollbars="horizontal"
android:scrollbars="vertical|horizontal"
例如:
<android.support.v4.widget.NestedScrollView
android:id="@+id/foo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v4.widget.NestedScrollView>
文档 link:https://developer.android.com/reference/android/view/View.html#attr_android:scrollbars