build.gradle- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:23.0.0'
- compile 'com.android.support:cardview-v7:23.0.0'
- compile 'com.android.support:design:23.0.0'
- }
複製代碼 layout/cardview.xml- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout 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:orientation="vertical">
- <android.support.v7.widget.CardView
- android:id="@+id/view"
- android:layout_width="match_parent"
- android:layout_height="120dp"
- android:layout_gravity="center_horizontal"
- android:layout_margin="10dp"
- app:cardBackgroundColor="#b7d1ff"
- app:cardCornerRadius="15dp"
- app:cardElevation="5dp">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center_horizontal">
- <ImageView
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:id="@+id/imageView"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true"
- android:src="@mipmap/ic_launcher" />
- </RelativeLayout>
- </android.support.v7.widget.CardView>
- </LinearLayout>
複製代碼 drawable/ic_grade.xml- <vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#fffbb9"
- android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
- </vector>
複製代碼 layout/activity_main.xml- <?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"
- tools:context=".MainActivity">
- <android.support.design.widget.AppBarLayout
- android:id="@+id/appbar"
- android:layout_width="match_parent"
- android:layout_height="240dp">
- <android.support.design.widget.CollapsingToolbarLayout
- android:id="@+id/collapsingToolbar"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:contentScrim="@color/colorPrimary"
- app:layout_scrollFlags="scroll|exitUntilCollapsed"
- app:title="@string/app_name">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerCrop"
- android:src="@drawable/shutterstock"
- app:layout_collapseMode="parallax" />
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"/>
- </android.support.design.widget.CollapsingToolbarLayout>
- </android.support.design.widget.AppBarLayout>
- <android.support.design.widget.FloatingActionButton
- android:id="@+id/fab"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:src="@drawable/ic_grade"
- app:backgroundTint="#aa008a"
- app:rippleColor="#ff00e5"
- app:layout_anchor="@id/appbar"
- app:layout_anchorGravity="right|bottom"/>
- <!--app:layout_anchor="@id/collapsingToolbar"
- 需anchor在appbar上才具縮放效果-->
- <android.support.v4.widget.NestedScrollView
- android:id="@+id/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="match_parent"
- android:orientation="vertical">
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview" />
- </LinearLayout>
- </android.support.v4.widget.NestedScrollView>
- </android.support.design.widget.CoordinatorLayout>
複製代碼 |