Android开发之路--卡片式布局CardView的使用以及轮播图代码

本文详细介绍了Android开发中如何使用CardView创建卡片式布局,并结合步骤讲解了轮播图的实现,包括导入依赖、布局设计、适配器设置以及Java代码的编写。

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

思路

第一步:导入依赖

在app/build.gradle中添加依赖

 	implementation 'com.youth.banner:banner:1.4.9' //轮播图
    compile 'com.android.support:recyclerview-v7:26.1.0'//比listview还好用的控件
    compile 'com.android.support:cardview-v7:26.1.0'//卡片布局
    compile 'com.github.bumptech.glide:glide:3.7.0'//图片加载框架
    implementation 'com.squareup.okhttp3:okhttp:3.4.1'//网络请求框架

第二步:添加布局

//在mainactivity.xml添加

		//卡片式布局
  <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            </LinearLayout>
	
		//轮播图
	 <com.youth.banner.Banner
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/banner"
                    android:layout_width="match_parent"
                    android:layout_height="150dp" />


//fragment_home_cardview.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="5dp"
    app:cardCornerRadius="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/imageView1"
            android:layout
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值