Android(安卓)-------CardView

时间:2023-03-08 21:47:46

Android(安卓)-------CardView

1.activity_main.xml

<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
> <LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"> <ImageView
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:scaleType="centerCrop"
android:src="@drawable/sng" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="棒冰行动"
android:textSize="18sp"
android:textStyle="bold" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="棒冰行动,公益传播设计夏令营" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

2.MainActivity.class

package com.example.administrator.myfirst;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.support.v7.widget.CardView;

public class MainActivity extends AppCompatActivity {

private CardView cardView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); cardView = (CardView)findViewById(R.id.cardView); cardView.setRadius(8);//设置图片圆角的半径大小 cardView.setCardElevation(8);//设置阴影部分大小 cardView.setContentPadding(5,5,5,5);//设置图片距离阴影大小
}

}