依赖
compile 'com.android.support:cardview-v7:26+'
布局文件
<android.support.v7.widget.CardView
android:id="@+id/cardView"
app:cardCornerRadius="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/tu"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/er"/>
<TextView
android:id="@+id/tt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#3ff70000"
android:layout_marginTop="270dp"
android:text="棒冰行动,公益传播设计夏令营" />
<TextView
android:layout_below="@id/tt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123456789zxcvbnm"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Main的代码public class CardViewActivity extends AppCompatActivity {
private CardView cardView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_view);
cardView = (CardView)findViewById(R.id.cardView);
cardView.setRadius(15);//设置图片圆角的半径大小
cardView.setCardBackgroundColor(12);
cardView.setCardElevation(5);//设置阴影部分大小
cardView.setCardElevation(10);//设置Z轴阴影
cardView.setContentPadding(5,5,5,8);//设置图片距离阴影大小
}
}