1. 总的布局文件
<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:orientation="vertical"
tools:context="com.gx.gxzx.ui.realtime.commonElec.CommonElecActivity">
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:paddingTop="20dp"
app:contentInsetStart="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/my_toolbar_back"
android:src="@drawable/ic_back_white"
android:background="?controlBackground"
android:layout_margin="10dp"
android:layout_centerVertical="true"
android:layout_width="25dp"
android:layout_height="25dp" />
<ImageView
android:id="@+id/my_toolbar_loading"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/my_toolbar_title"
android:layout_width="25dp"
android:layout_marginRight="10dp"
android:layout_height="25dp" />
<TextView
android:id="@+id/my_toolbar_title"
android:text="tltie"
android:textColor="@color/white"
android:textSize="@dimen/title"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<com.gx.gxzx.widget.MyDeviceSelector
android:id="@+id/my_device_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
....
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</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 可以添加菜单按钮