返回列表 發帖
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"
  5.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  6.     android:paddingRight="@dimen/activity_horizontal_margin"
  7.     android:paddingTop="@dimen/activity_vertical_margin"
  8.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  9.     android:orientation="vertical"
  10.     android:weightSum="1">

  11.     <android.support.v7.widget.CardView
  12.         android:layout_width="match_parent"
  13.         android:layout_height="wrap_content"
  14.         android:id="@+id/view1"
  15.         app:cardBackgroundColor="#ffd0d0"
  16.         app:cardCornerRadius="12dp"
  17.         app:cardElevation="5dp">

  18.         <RelativeLayout
  19.             android:layout_width="match_parent"
  20.             android:layout_height="match_parent">

  21.             <ImageView
  22.                 android:layout_width="80dp"
  23.                 android:layout_height="80dp"
  24.                 android:id="@+id/imageView1"
  25.                 android:layout_centerVertical="true"
  26.                 android:layout_alignParentStart="true"
  27.                 android:layout_marginLeft="20dp"
  28.                 android:src="@mipmap/ic_launcher" />

  29.             <TextView
  30.                 android:layout_width="wrap_content"
  31.                 android:layout_height="wrap_content"
  32.                 android:text="CardView #1"
  33.                 android:id="@+id/textView1"
  34.                 android:layout_marginStart="53dp"
  35.                 android:textSize="25sp"
  36.                 android:layout_centerVertical="true"
  37.                 android:layout_toEndOf="@+id/imageView1" />

  38.         </RelativeLayout>
  39.     </android.support.v7.widget.CardView>

  40.     <android.support.v7.widget.CardView
  41.         android:layout_width="match_parent"
  42.         android:layout_height="wrap_content"
  43.         android:id="@+id/view2"
  44.         android:layout_marginTop="20dp"
  45.         android:layout_marginBottom="20dp">

  46.         <RelativeLayout
  47.             android:layout_width="match_parent"
  48.             android:layout_height="match_parent">

  49.             <ImageView
  50.                 android:layout_width="80dp"
  51.                 android:layout_height="80dp"
  52.                 android:id="@+id/imageView2"
  53.                 android:layout_centerVertical="true"
  54.                 android:layout_alignParentStart="true"
  55.                 android:layout_marginLeft="20dp"
  56.                 android:src="@mipmap/ic_launcher" />

  57.             <TextView
  58.                 android:layout_width="wrap_content"
  59.                 android:layout_height="wrap_content"
  60.                 android:text="CardView #2"
  61.                 android:id="@+id/textView2"
  62.                 android:layout_marginStart="53dp"
  63.                 android:textSize="25sp"
  64.                 android:layout_centerVertical="true"
  65.                 android:layout_toEndOf="@+id/imageView2" />

  66.         </RelativeLayout>
  67.     </android.support.v7.widget.CardView>

  68.     <android.support.v7.widget.CardView
  69.         android:layout_width="match_parent"
  70.         android:layout_height="wrap_content"
  71.         android:id="@+id/view3">

  72.         <RelativeLayout
  73.             android:layout_width="match_parent"
  74.             android:layout_height="match_parent">

  75.             <ImageView
  76.                 android:layout_width="80dp"
  77.                 android:layout_height="80dp"
  78.                 android:id="@+id/imageView3"
  79.                 android:layout_centerVertical="true"
  80.                 android:layout_alignParentStart="true"
  81.                 android:layout_marginLeft="20dp"
  82.                 android:src="@mipmap/ic_launcher" />

  83.             <TextView
  84.                 android:layout_width="wrap_content"
  85.                 android:layout_height="wrap_content"
  86.                 android:text="CardView #3"
  87.                 android:id="@+id/textView3"
  88.                 android:layout_marginStart="53dp"
  89.                 android:textSize="25sp"
  90.                 android:layout_centerVertical="true"
  91.                 android:layout_toEndOf="@+id/imageView3" />

  92.         </RelativeLayout>
  93.     </android.support.v7.widget.CardView>


  94. </LinearLayout>
複製代碼
  1. package com.example.student.myapplication;

  2. import android.graphics.Color;
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.support.v7.widget.CardView;

  6. public class MainActivity extends AppCompatActivity {
  7.     CardView cd1,cd2;

  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.activity_main);
  12.         cd1= (CardView) findViewById(R.id.view2);
  13.         cd2= (CardView) findViewById(R.id.view3);
  14.         cd1.setCardElevation(5);
  15.         cd1.setRadius(12);
  16.         cd1.setCardBackgroundColor(Color.parseColor("#7fff7d"));
  17.         cd2.setCardElevation(8);
  18.         cd2.setRadius(20);
  19.         cd2.setCardBackgroundColor(Color.parseColor("#3f89f9"));
  20.     }
  21. }
複製代碼
كخخخخخخخخخخخخخ

TOP

返回列表