Android Meterial Design 之 Coordi

2016-12-09  本文已影响0人  I呀IT小胖

1.简介 :

2.使用:

<android.support.v4.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">

</android.support.v4.widget.NestedScrollView>


 - **AppBarLayout :** 
 <blockquote> AppBarLayout 的子View 通过ScrollFlags来执行指定动作,可以设置4种动作 注: 默认是不滚动,在什么位置就是什么位置,可以设置多种flag 使用 | 隔开</blockquote>
      <ul>
    <li>scroll</li>会根据滚动而滚出屏幕,所有需要在滚动时滚出屏幕的都需要设置
    <li>enterAlways</li>快速返回模式。 向上滚动 设置次flag的view隐藏,向下滚动view显示
<li>enterAlwaysCollapsed</li>当你的视图已经设置minHeight属性又使用此标志时,当view向下滑动的时候会显示最小的高度,只有当滚动视图到达顶部时才显示到view的完整高度。
<li>exitUntilCollapsed</li>在滚动过程中,会先将view缩小到最小高度,在达到此view最小高度之前,整个视图中的滑动事件是不生效的,达到之后,才会滑动视图.
<ul>

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/barLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
**app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" **
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>```

所以最终的布局是

<android.support.design.widget.CoordinatorLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"    
  xmlns:app="http://schemas.android.com/apk/res-auto" 
  android:id="@+id/coordinatorLayout"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout    
    android:id="@+id/barLayout"    
    android:layout_width="match_parent"  
    android:layout_height="wrap_content" 
     android:fitsSystemWindows="true"> 
   <android.support.v7.widget.Toolbar        
        app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"      
        android:id="@+id/toolbar"       
        android:layout_width="match_parent"       
        android:layout_height="?android:attr/actionBarSize"    
        android:background="?attr/colorPrimary"       />
</android.support.design.widget.AppBarLayout>   

       <android.support.v4.widget.NestedScrollView        
    app:layout_behavior="@string/appbar_scrolling_view_behavior"    
    android:layout_width="match_parent"        
    android:layout_height="match_parent">    
<!--内容子布局-->    
      </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

3.总结
有了这些个控件,实现起很多好看的效果就显得非常容易
本文只是说一下普通用法,在我公司的app当中我实现了很多不同的效果,用法有很多,实现的效果有非常多种,大家一起学习,共同成长.

上一篇下一篇

猜你喜欢

热点阅读