zoukankan      html  css  js  c++  java
  • RecyclerView 网格布局

    上面我们介绍的就是?RecyclerView 线性布局的使用,效果还是不错的,一般可以用于浏览个人信息列表操作。接着,我们来看第二种布局形式:网格布局。

    ? ? 网格布局也是非常常用的,一般用于图片相册的浏览,接下来的工作就是复制粘贴一下原先的代码就可以了,因为适配器里面的代码几乎一个样,我们可以考虑把它封装起来用,不过现在还是怎么方便怎么来。

    ? ? 对于线性布局来说,网格布局是需要做一定量的修改的,也就是布局文件的修改,我们把旁边的 “我是一只...” 文本给去掉,保留了图片和动物名称,所以布局文件代码修改为:

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

    <RelativeLayout(http://www.my516.com)
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp">

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

    <TextView
    android:id="@+id/tv_recy_item_2_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/img_recy_item_2_pic"
    android:layout_centerInParent="true"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:textSize="18sp" />

    </RelativeLayout>
    </android.support.v7.widget.CardView>
    ---------------------

  • 相关阅读:
    AsyncTask,MailTask,ScheduledTask
    Mysql的事务理解
    MySQL初识
    HTTP 的原理零散知识点
    SpringBoot简单搭建开发
    Android 的生命周期
    C51 虚拟元器件
    JavaSE 知识整合 (更新中……)
    java关键字篇
    Android开启网络权限
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11359731.html
Copyright © 2011-2022 走看看