卡片式布局CardView的使用以及轮播图代码
思路
第一步:导入依赖
在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