RecyclerView+Glide+CardView实现瀑布流效果

本文介绍了如何在Android中利用RecyclerView、Glide和CardView实现瀑布流效果,包括导入依赖、XML布局设计以及Java代码实现。在实现过程中,需要注意图片不显示的解决方法和在Fragment中使用RecyclerView的注意事项。
摘要由CSDN通过智能技术生成

设计思路

在类微信小程序首页框架(一)的基础上,修改了图标样式,并在发现页面将以前的文本框改为瀑布流效果的图片浏览。

1.导入依赖

在下图目录中的build.gradle中的dependencies加入下列语句
在这里插入图片描述

	implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    implementation 'androidx.cardview:cardview:1.0.0'

2.页面布局(.xml文件的编写)

.xml文件都在/res/layout目录下

2.1 fragment_find.xml文件

添加recyclerview控件

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </androidx.recyclerview.widget.RecyclerView>
2.2 item_recycler.xml文件

包含文本控件和ImageView控件,用CardView作为父容器进行包裹

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    card_view:cardCornerRadius="5dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp">


        <ImageView
            android:id="@+id/bird_image"
            android:layout_width="150dp"
            android:layout_height="80dp"
            android:layout_marginRight
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值