AppbarLayout相关

1:底部阴影问题

          app:elevation="0dp": 去除阴影

2:Failed to find style 'coordinatorLayoutStyle' in current theme

     使用CoordinatorLayout报的错,解决办法--

 apptheme中添加:

<item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>

言归正传,下面是整个的layout

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/main_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           >
            <android.support.v7.widget.Toolbar
                android:id="@+id/main_toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                app:layout_scrollFlags="scroll"
                app:title="导航栏"
                app:titleTextColor="#FFFFFF"></android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="none"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/tv_conent" />
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>

在上面的布局中我们可以看到 NestedScrollView中添加了一个app:layout_behavior="@string/appbar_scrolling_view_behavior"的属性,这个属性是系统的behavior,字面意思为appbar设置一个滚动的behavior,

 3:layout_scrollFlags

 scroll:当设置scroll时,appbarlayout会与下面设置的NestedScrollView同步滚动;

 enterAlways:当设置为这个值时,NestedScrollView只要往下滚动,appbarlayout就会掉下来,单独设置这个值看不出来,我们可以将属性设置为app:layout_scrollFlags="scroll|enterAlways",查看效果。

exitUntilCollapsed:当设置exitUntilCollapsed时,通常与minHeight同时设置,当向上滑动时,appbarlayout首先达到minHeight时,滑动事件才会交给NestedScrollView,当向下滑动时,NestedScrollView完全可见后,appbarlayout才慢慢掉下来。

enterAlwaysCollapsed:将属性设置为app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"时,当用户上滑时可将appbarlayout完全不可见,下滑时,appbarlayout首先掉到minheight的位置,然后当NestedScrollView滑动的最顶部时,appbarLyout才会慢慢显示完全。

snap:主要是一个吸附的效果,根据滑动的位置自动弹回还是完全隐藏。

4:CollapsingToolbarLayout 

 可折叠的,当全部可见时,title最大,当滑动移除屏幕时逐渐变小。

 <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:title="@string/app_name"
                >
                <android.support.v7.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:id="@+id/tool_bar"
                    ></android.support.v7.widget.Toolbar>

 </android.support.design.widget.CollapsingToolbarLayout>

 其中contentScrim属性设置纱布的颜色,当滑动到内部toolbar的高度时,纱布颜色显示。

 

 

5:其他属性

setExpanded(boolean expanded)设置是否展开

addOnOffsetChangedListener当appbarLayout发生偏移时的回调。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值