Android Material Design Android官方控件之學習
NestedScrollView
5.0以後 NestedScrollView用來實現ScrollView並且可以實現嵌套滾動效果。
- 用法與ScrollView一樣,如只有一個子佈局。
- 增加作爲CoordinatorLayout子佈局,通過behavior跟CoordinatorLayout進行互動。
導入support-v4庫,一般創建項目就已經依賴v4庫
'com.android.support:support-v4:26.1.0'
一般用法與ScrollView一樣
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:background="#cdcdcd"
android:text="這裏簡單展示跟ScrollView一樣的用法,關鍵用法請看下面AppBarLayoutActivity"
android:layout_height="400dp"/>
<TextView
android:layout_width="match_parent"
android:background="#ababab"
android:layout_height="400dp"/>
<TextView
android:layout_width="match_parent"
android:background="#fafafa"
android:layout_height="400dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
通過behavior跟CoordinatorLayout進行互動
app:layout_behavior="@string/appbar_scrolling_view_behavior"