本帖最後由 tonyh 於 2018-4-28 18:23 編輯
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="8dp"
- 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>
複製代碼 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="wrap_content"
- app:elevation="10dp">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/colorPrimary"
- app:layout_scrollFlags="scroll|enterAlways"
- app:title="@string/app_name"
- app:titleTextColor="#d7e9ff" />
- </android.support.design.widget.AppBarLayout>
- <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/cardview2" />
- <include layout="@layout/cardview3" />
- <include layout="@layout/cardview2" />
- <include layout="@layout/cardview" />
- <include layout="@layout/cardview3" />
- <include layout="@layout/cardview2" />
- </LinearLayout>
- </android.support.v4.widget.NestedScrollView>
- </android.support.design.widget.CoordinatorLayout>
複製代碼 |