使用CoordinatorLayout实现折叠式ToolBar
来源:互联网 发布:人工智能在安防行业 编辑:程序博客网 时间:2024/04/30 15:03
转载请注明出处:http://blog.csdn.net/liu1252247624/article/details/51596860
效果图:
要使用CoordinatorLayout先在gradle中加入compile 'com.android.support:design:23.4.0'
Activity布局:
<?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.lg.collapsingdemo.ScrollingActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="350dp" android:fitsSystemWindows="true" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_scrolling"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/large_text"/> </android.support.v4.widget.NestedScrollView></android.support.design.widget.CoordinatorLayout>
app:title设置的Title内容在布局展开的时候会变得大些,而在折叠的时候使字体过渡到默认值,注意,我们的title是在CollapsingToolbarLayout上面设置的,而不是在ToolBar上面
app:layout_collapseMode这个属性来设置子视图折叠模式,有两种:
固定模式:app:layout_collapseMode = "pin" 确保Toolbar在view折叠的时候最后固定在屏幕的顶部。
视差模式:app:layout_collapseMode = "parallax" 在折叠的时候会有个视差折叠的效果。
app:layout_scrollFlags属性设置滑动的方式,以起到响应布局的作用
通过app:layout_behavior="@string/appbar_scrolling_view_behavior"属性来实现滚动布局。
Activity代码:
public class ScrollingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scrolling); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_scrolling, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
源码地址:http://download.csdn.net/detail/liu1252247624/9542712
1 0
- 使用CoordinatorLayout实现折叠式ToolBar
- 实现折叠式Toolbar:CollapsingToolbarLayout 使用完全解析
- 实现折叠式Toolbar:CollapsingToolbarLayout 使用完全解析
- CoordinatorLayout + AppBarLayout实现滑动隐藏ToolBar
- CoordinatorLayout、Tablayout、Toolbar简单组合使用
- recyclerview,AppBarLayout,Toolbar,CoordinatorLayout 的结合使用~
- CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout、Toolbar混合使用经验
- Material Design之CoordinatorLayout+AppBarLayout实现上滑隐藏ToolBar-----Material Design使用---
- Meterial Design最佳体验(1): 使用Toolbar, CoordinatorLayout, AppBarLayout等实现精美标题栏
- 实战CoordinatorLayout+Toolbar,CoordinatorLayout+CollapsingToolbarLayout
- Material Design之CoordinatorLayout+AppBarLayout实现上滑隐藏ToolBar
- 【Android UI】CoordinatorLayout实现带图片可拉伸的Toolbar
- CoordinatorLayout实现上滑隐藏ToolBar遇到的问题
- Material Design 之 CoordinatorLayout + AppBarLayout 实现上滑隐藏ToolBar
- CoordinatorLayout与CollapsingToolbarLayout实现视差滚动动画和Toolbar滚动
- Android CoordinatorLayout+AppBarLayout实现toolbar背景渐变透明
- CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+Toolbar实现app的折叠效果
- Material Design之CoordinatorLayout+AppBarLayout实现上滑隐藏ToolBar
- Qt如何在main.cpp里面添加connect函数
- git提交时候需要注意的问题(如何控制不想提交的文件)
- Android闪白屏黑屏问题解决办法
- hdu 1717 && 计蒜课 52 【分数小数的互相转化】【数论?】
- 也谈一下Activiti工作流节点的自由跳转
- 使用CoordinatorLayout实现折叠式ToolBar
- 开启ActiveMQ时加载指定路径下的配置文件
- 导入maven项目时,包不存在导致出错的问题。
- TCP状态变迁图
- L2-009. 抢红包
- IOS时间与日期处理
- Android中防止重复点击的小技巧
- 获取服务器时间。
- ImageLoader源码解析