Android Design Support之scroll 初探

来源:互联网 发布:java加密算法有哪些 编辑:程序博客网 时间:2024/05/16 08:59

step1

将ScrollView 替换为NestedScrollView

step2

在想要同样效果的控件加上属性app:layout_scrollFlags=”scroll|enterAlways”即可

layout=”@layout/app_bar_drawer”

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true"    tools:context="com.faith.smile.copy.drawer">    <android.support.design.widget.AppBarLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:theme="@style/AppTheme.AppBarOverlay">        <android.support.v7.widget.Toolbar            android:id="@+id/toolbar"            android:layout_width="match_parent"            android:layout_height="?attr/actionBarSize"            android:background="?attr/colorPrimary"            app:layout_scrollFlags="scroll|enterAlways"            app:popupTheme="@style/AppTheme.PopupOverlay" />        <android.support.design.widget.TabLayout            android:id="@+id/tab_layout"            android:layout_width="match_parent"            android:layout_height="wrap_content"            app:layout_scrollFlags="scroll|enterAlways">        </android.support.design.widget.TabLayout>    </android.support.design.widget.AppBarLayout>    <include layout="@layout/content_drawer" />    <android.support.design.widget.FloatingActionButton        android:id="@+id/fab"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="bottom|end"        android:layout_margin="@dimen/fab_margin"        android:src="@android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>

layout=”@layout/content_drawer”

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    app:layout_behavior="@string/appbar_scrolling_view_behavior"    tools:context="com.faith.smile.copy.drawer"    tools:showIn="@layout/app_bar_drawer">    <android.support.v4.widget.NestedScrollView        android:layout_width="match_parent"        android:layout_height="wrap_content">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />v            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button3" />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="button4" />        </LinearLayout>    </android.support.v4.widget.NestedScrollView></RelativeLayout>
0 0
原创粉丝点击