zoukankan      html  css  js  c++  java
  • RecyclerView 瀑布流布局

    最后一个布局样式是瀑布流的布局,其实和网格布局几乎一样的,网格布局是规规矩矩的,而瀑布流就是有长有短的那种,有错位和落差感,有时候太规矩的不好看,有一点错位显得更加美观。

    ? ? 瀑布流的?RecyclerView Item 布局文件要注意了,不能写固定的一个高度,否则就没有效果了。比如,我们得这样改:

    <?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_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    app:cardCornerRadius="8dp"
    app:cardElevation="4dp">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp">

    <ImageView
    android:id="@+id/img_recy_item_3_pic"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:scaleType="centerCrop" />

    <TextView
    android:id="@+id/tv_recy_item_3_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/img_recy_item_3_pic"
    android:layout_centerInParent="true"
    android:layout_marginTop="8dp"
    android:textSize="16sp" />

    </RelativeLayout>
    </android.support.v7.widget.CardView>
    ? ? 注意上面的代码,cardview 的高度不能固定,以及下面的 textview 高度也都不能固定值,都要写为 wrap_content,适配器就不需要修改了,要改的地方就是数据格式还有?RecyclerView 的布局管理样式。

    我们添加数据要改为这样,名称有长的有短的,才能形成长短不一的瀑布流的形式。

    private void addStaggeredData() {
    Map<String, Object> map = null;
    Random random = new Random();
    String[] str = {
    "瀑布流 ",
    "瀑布流 瀑布流 ",
    "瀑布流 瀑布流 瀑布流 ",
    "瀑布流 瀑布流 瀑布流 瀑布流 ",
    };

    for (int i = 0; i < 30; i++) {
    int n = random.nextInt(pics.length);
    map = new HashMap<>(http://www.amjmh.com/v/BIBRGZ_558768/);
    map.put("pic", pics[n]);
    map.put("name", names[n] + " " + str[random.nextInt(str.length)]);
    staggeredData.add(map);
    }
    }
    ---------------------

  • 相关阅读:
    org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [0, 1, param1, param2]
    在Springboot中Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]问题
    Springcould学习总结
    XXl-job基于springbooot的基本配置
    Nginx反向代理简单配置
    redis哨兵机制及配置
    redis的主从复制
    jedis在Java环境操作redis
    liunx环境redis的安装
    express之cookie和session
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11347016.html
Copyright © 2011-2022 走看看