1. 总的布局文件
1<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:app="http://schemas.android.com/apk/res-auto" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 tools:context="com.gx.gxzx.ui.realtime.commonElec.CommonElecActivity"> 8 <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 xmlns:app="http://schemas.android.com/apk/res-auto"> 12 <android.support.design.widget.CollapsingToolbarLayout 13 android:layout_width="match_parent" 14 app:layout_scrollFlags="scroll|enterAlways|snap" 15 android:layout_height="wrap_content"> 16 <android.support.v7.widget.Toolbar 17 android:id="@+id/my_toolbar" 18 android:paddingTop="20dp" 19 app:contentInsetStart="0dp" 20 android:layout_width="match_parent" 21 android:layout_height="wrap_content"> 22 <RelativeLayout 23 android:layout_width="match_parent" 24 android:layout_height="wrap_content"> 25 <android.support.v7.widget.AppCompatImageButton 26 android:id="@+id/my_toolbar_back" 27 android:src="@drawable/ic_back_white" 28 android:background="?controlBackground" 29 android:layout_margin="10dp" 30 android:layout_centerVertical="true" 31 android:layout_width="25dp" 32 android:layout_height="25dp" /> 33 <ImageView 34 android:id="@+id/my_toolbar_loading" 35 android:layout_centerVertical="true" 36 android:layout_toLeftOf="@+id/my_toolbar_title" 37 android:layout_width="25dp" 38 android:layout_marginRight="10dp" 39 android:layout_height="25dp" /> 40 <TextView 41 android:id="@+id/my_toolbar_title" 42 android:text="tltie" 43 android:textColor="@color/white" 44 android:textSize="@dimen/title" 45 android:gravity="center" 46 android:layout_centerInParent="true" 47 android:layout_width="wrap_content" 48 android:layout_height="wrap_content" /> 49 </RelativeLayout> 50 </android.support.v7.widget.Toolbar> 51 </android.support.design.widget.CollapsingToolbarLayout> 52 <com.gx.gxzx.widget.MyDeviceSelector 53 android:id="@+id/my_device_selector" 54 android:layout_width="match_parent" 55 android:layout_height="wrap_content"/> 56 </android.support.design.widget.AppBarLayout> 57 <android.support.v4.widget.SwipeRefreshLayout 58 android:id="@+id/swipe_refresh_layout" 59 android:layout_width="match_parent" 60 android:layout_height="match_parent" 61 app:layout_behavior="@string/appbar_scrolling_view_behavior"> 62 <android.support.v4.widget.NestedScrollView 63 android:layout_width="match_parent" 64 android:layout_weight="1" 65 android:layout_height="0dp"> 66 .... 67 </android.support.v4.widget.NestedScrollView> 68 </android.support.v4.widget.SwipeRefreshLayout> 69 70 71</android.support.design.widget.CoordinatorLayout>
#2. 要点 ##2.1 app:contentInsetStart="0dp"
会使toolbar里面的View会扩充到左右,不会有间隙。
2.2 android:background="?controlBackground"
这个点击效果不错,圆形的灰色背景
2.3 下拉刷新
SwipeRefreshLayout 要包裹着NestedScrollView才会有下拉效果
2.4 ActionMenuView
ActionMenuView 可以添加菜单按钮