android之DesignSupport
来源:互联网 发布:cadence软件仿真教程 编辑:程序博客网 时间:2024/06/06 06:33
上图:
import android.os.Bundle;import android.support.design.widget.CollapsingToolbarLayout;import android.support.design.widget.CoordinatorLayout;import android.support.design.widget.FloatingActionButton;import android.support.design.widget.Snackbar;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.view.View;public class MainActivity extends AppCompatActivity { private FloatingActionButton btn_fab; private CoordinatorLayout fl; // private Toolbar topBar; private CollapsingToolbarLayout collToolbarll; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); fl= (CoordinatorLayout) findViewById(R.id.main_layout); btn_fab= (FloatingActionButton) findViewById(R.id.btn_fab); topBar= (Toolbar) findViewById(R.id.topBar); //setSupportActionBar(topBar); collToolbarll= (CollapsingToolbarLayout) findViewById(R.id.CollapsingToolbarLayout); collToolbarll.setTitle("AppBarLayout,CollapsingToolbarLayout,Toolbar"); btn_fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(fl, "hellow,Snackbar", Snackbar.LENGTH_LONG).setAction("知道了", new View.OnClickListener() { @Override public void onClick(View v) { } }).show(); } }); }}
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:id="@+id/main_layout"> <!--向上滑动,toolbar消失,向下滑动,toolbar出现 app:layout_scrollFlags="scroll|enterAlways",可以用在Toolbar,CollapsingToolbarLayout中 CoordinatorLayout可以让布局具有过度动画效果 AppBarLayout为了让Toolbar适配CoordinatorLayout CollapsingToolbarLayout为了让Tolbar有折叠效果 app:layout_collapseMode="pin" 让折叠后剩下toolbar app:expandedTitleMarginStart="100dp"文字得距离 app:layout_collapseMode="parallax"让imageView滑动更有感觉 当把toolbar得背景去掉, 即去掉android:background="#77db93",则就不显示toolbar,只剩下图片。 然后在CollapsingToolbarLayout中添加app:contentScrim="#77bd93",则图片向上移动,显示toolbar --><android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="300dp"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/CollapsingToolbarLayout" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:expandedTitleMarginStart="100dp" > <ImageView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_collapseMode="parallax" android:src="@drawable/mm" android:scaleType="fitXY"/> <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="#77db93" android:id="@+id/topBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:layout_collapseMode="pin" /> </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" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> </LinearLayout></android.support.v4.widget.NestedScrollView> <android.support.design.widget.FloatingActionButton android:id="@+id/btn_fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:src="@mipmap/ic_launcher" android:layout_margin="10dp" app:fabSize="normal" /></android.support.design.widget.CoordinatorLayout>
0 0
- android之DesignSupport
- Android之 Android 虚拟机
- Android之 Android 虚拟机
- Android之android:launchMode
- Android之android:launchMode
- Android之android:launchMode
- Android之android:launchMode
- Android 之 Android Studio
- 【Android】Android之创建活动
- 【Android】Android之intent
- android之android-autofittextview
- android 学习之---Android之GoogleMap(转)
- android高手之路之Android Widget
- Android学习之路之Android基本知识
- android之ArrayAdaper之Spinner
- android Preference之android:dependency
- Android基础之Android硬件
- android之 Android消息机制
- 一 swift之UICollectionView纯代码cell的复用、footerView的添加
- 数据结构——距离根节点为k的节点
- java通过SMTP发送QQ邮件的完全步骤
- 思维导图
- JavaScript创建对象的几种方式
- android之DesignSupport
- Ubuntu构筑LiteIDE的Go语言开发环境
- [JZOJ 4832]高维宇宙
- 【C语言】——union共用体
- Spring框架介绍
- 遗传算法的简单实现(1):求解函数最大值
- C#中的反射
- 【GDOI2017模拟12.3】告别
- php判断相同文件