Android_cardview的使用

本文介绍了一个使用Android Support Library中的CardView组件实现的具体布局案例。该布局包含一张全宽图片、一个顶部覆盖的标题以及一段描述文字,并展示了如何通过Java代码调整CardView的样式属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

依赖  
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);//设置图片距离阴影大小
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值