国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

學習使用Material Design控件(四)Android實現標題欄自動縮放、放大效果

2019-10-22 18:31:28
字體:
來源:轉載
供稿:網友

本文要實現內容移動時,標題欄自動縮放/放大的效果,效果如下:

Material,Design

控件介紹

這次需要用到得新控件比較多,主要有以下幾個:

CoordinatorLayout
組織它的子views之間協作的一個Layout,它可以給子View切換提供動畫效果。
AppBarLayout
可以讓包含在其中的控件響應被標記了ScrollingViewBehavior的View的滾動事件
CollapsingToolbarLayout
可以控制包含在CollapsingToolbarLayout其中的控件,在響應collapse時是移除屏幕和固定在最上面
TabLayout
結合ViewPager,實現多個TAB的切換的功能
NestedScrollView
與ScrollView基本相同,不過包含在NestedScrollView中的控件移動時才能時AppBarLayout縮放

Layout布局

<?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”  android:layout_width=“match_parent”  android:layout_height=“match_parent”  android:fitsSystemWindows=“true”>  <android.support.design.widget.AppBarLayout    android:layout_width=“match_parent”    android:layout_height=“256dp”    android:fitsSystemWindows=“true”    android:theme=“@style/ThemeOverlay.AppCompat.Dark.ActionBar”>    <android.support.design.widget.CollapsingToolbarLayout      android:id=“@+id/collapsing_toolbar”      android:layout_width=“match_parent”      android:layout_height=“match_parent”      android:fitsSystemWindows=“true”      app:contentScrim=“?attr/colorPrimary”      app:expandedTitleMarginEnd=“64dp”      app:expandedTitleMarginStart=“48dp”      app:layout_scrollFlags=“scroll|exitUntilCollapsed”>      <ImageView        android:id=“@+id/ivImage”        android:layout_width=“match_parent”        android:layout_height=“match_parent”        android:fitsSystemWindows=“true”        android:scaleType=“centerCrop”        android:src=“@drawable/book1”        app:layout_collapseMode=“parallax”        app:layout_collapseParallaxMultiplier=“0.7” />      <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/ThemeOverlay.AppCompat.Light” />    </android.support.design.widget.CollapsingToolbarLayout>  </android.support.design.widget.AppBarLayout>  <LinearLayout    android:layout_width=“match_parent”    android:layout_height=“match_parent”    android:orientation=“vertical”    app:layout_behavior=“@string/appbar_scrolling_view_behavior”>    <android.support.design.widget.TabLayout      android:id=“@+id/sliding_tabs”      android:layout_width=“match_parent”      android:layout_height=“wrap_content”      app:tabGravity=“fill”      app:tabMode=“fixed” />    <android.support.v4.view.ViewPager      android:id=“@+id/viewpager”      android:layout_width=“match_parent”      android:layout_height=“match_parent” />  </LinearLayout></android.support.design.widget.CoordinatorLayout>

CollapsingToolbarLayout和TabLayout的使用說明可以參考探索新的Android Material Design支持庫

代碼實現

//Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() {   @Override   public void onClick(View view) {     onBackPressed();   } });//使用CollapsingToolbarLayout后,title需要設置到CollapsingToolbarLayout上 CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle("失控");//設置ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(mViewPager);//給TabLayout增加Tab, 并關聯ViewPager TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); tabLayout.addTab(tabLayout.newTab().setText("內容簡介")); tabLayout.addTab(tabLayout.newTab().setText("作者簡介")); tabLayout.addTab(tabLayout.newTab().setText("目錄")); tabLayout.setupWithViewPager(mViewPager);

詳細代碼參見這里

項目源碼已發布到Github,Material Design新控件基本介紹完了,
下篇文章會結合豆瓣讀書的API,整合一下這些控件,做一個Demo。
源碼地址:MaterialDesignExample

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巧家县| 古交市| 伽师县| 清水河县| 清河县| 英吉沙县| 麻栗坡县| 合作市| 民权县| 麻阳| 揭西县| 宁蒗| 阿克| 山阳县| 搜索| 滦南县| 巍山| 保靖县| 越西县| 乡城县| 新河县| 平舆县| 临城县| 南丹县| 扬州市| 皋兰县| 铁岭县| 新和县| 淳化县| 万载县| 巴青县| 独山县| 广灵县| 海淀区| 民和| 郴州市| 巴林左旗| 双柏县| 文成县| 保山市| 师宗县|