效果图:

实现步骤:

1、首先在 build.gradle 文件中引入 RecycleView

implementation 'com.android.support:recyclerview-v7:28.0.0'

添加完成后,在右上角有一个同步Sync Now的提示,点击进行同步构建,接下来修改activity_main.xml的代码

2、在 activity_main.xml 布局文件中加入RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>

接着创建RecyclerView的列表项布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="400dp"
android:gravity="center"> <TextView
android:id="@+id/time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" /> <View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#c0c0c0" /> <ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:layout_weight="2"
android:scaleType="fitCenter"
android:src="@drawable/image1" />
</LinearLayout>

3、然后创建 RecyclerView  的数据适配器

package com.newland.project3_4;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; public class MonitorAdapter extends RecyclerView.Adapter<MonitorAdapter.ViewHolder> {
private String[] times = {"2019年5月9日17时14分30秒", "2019年5月9日17时15分30秒", "2019年5月9日18时30分30秒", "2019年5月9日18时40分30秒", "2019年5月10日17时14分30秒"};
private int[] imageIds = {R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,R.drawable.image5}; @NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
} @Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.image.setImageResource(imageIds[position]);
holder.time.setText(times[position]);
} @Override
public int getItemCount() {
return times.length;
} static class ViewHolder extends RecyclerView.ViewHolder {
private ImageView image;//图片
private TextView time;//时间 public ViewHolder(View v) {
super(v);
image = v.findViewById(R.id.image);
time = v.findViewById(R.id.time);
}
}
}

最后设置 RecyclerView 的适配器

package com.newland.project3_4;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycler_view);
//创建线性布局管理器,方向垂直
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
//recyclerView设置布局管理器
recyclerView.setLayoutManager(linearLayoutManager);
MonitorAdapter adapter = new MonitorAdapter();
//添加Android自带的分割线
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
//设置适配器
recyclerView.setAdapter(adapter);
}
}

Android物联网应用程序开发(智慧园区)—— 图片预览界面的更多相关文章

  1. (干货)微信小程序之上传图片和图片预览

    这几天一直负责做微信小程序这一块,也可以说是边做边学习吧,把自己做的微信小程序的一些功能分享出来,与大家探讨一下,相互学习相互进步. 先看下效果图 只写了一下效果样式的话希望大家不要太在意,下面马路杀 ...

  2. 微信小程序之上传图片和图片预览

    这几天一直负责做微信小程序这一块,也可以说是边做边学习吧,把自己做的微信小程序的一些功能分享出来,与大家探讨一下,相互学习相互进步. 先看下效果图 只写了一下效果样式的话希望大家不要太在意,下面马路杀 ...

  3. 微信小程序开发之真机预览

    1:真机预览时上传组件的坑: 当在真机里面使用上传组件,当进入选择相片或者拍照的时候,小程序会进入后台,调用APP onHide()方法,选择完返回小程序是会调用App Onshow()方法,然后调用 ...

  4. Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面

    效果图: 自定义对话框布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...

  5. Android物联网应用程序开发(智慧园区)—— 园区监控系统界面

    效果图: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...

  6. Android物联网应用程序开发(智慧园区)—— 登录界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  7. Android物联网应用程序开发(智慧城市)—— 摄像头监控界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...

  8. Android物联网应用程序开发(智慧城市)—— 查询购物信息界面开发

    效果: 布局代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xm ...

  9. Android物联网应用程序开发(智慧城市)—— 用户注册界面开发

    效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...

随机推荐

  1. Oracle中常用的系统表

    1.dba开头的表 dba_users 数据库用户信息 dba_segments 表段信息 dba_extents 数据区信息 dba_objects 数据库对象信息 dba_tablespaces ...

  2. Android 基础UI组件(一)

    1.Toast //显示文字 Toast.makeText(this,"Toast显示文本",Toast.LENGTH_SHORT).show(); //显示图片 Toast to ...

  3. spring注解事务管理

    使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/b ...

  4. 计算机网络 Raw_Socket编程 Ping C语言

    计算机网络做了一个附加题,用C语言Raw_Socket实现ping指令. 通过本部的Mooc学习了一下Socket编程,然后成功写了出来orz 先放一下代码: #include <stdio.h ...

  5. shell脚本 mysqldump方式全备份mysql

    一.简介 源码地址 日期:2018/10/8 介绍:mysqldump方式全备份脚本,并保存固定天数的全备份 效果图: 二.使用 适用:centos6+ 语言:中文 注意:使用前先查看脚本,修改对应变 ...

  6. Python pyecharts绘制饼图

    一.pyecharts绘制饼图语法简介 饼图主要用于表现不同类目的数据在总和中的占比.每个的弧度不是数据量的占比pie.add()方法的用法add(name, attr, value, radius= ...

  7. canvas绘制圣诞树

    最近不知道咋的都玩起了用备忘录手绘圣诞树,作为万能的程序员,肯定也要跟上潮流,那用代码来实现圣诞树吧.哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈 实现效果如下: ...

  8. Python 字典是如何解决哈希冲突的

    本文主要翻译自 so 上面的问题 Why can a Python dict have multiple keys with the same hash? 下 Praveen Gollakota 的答 ...

  9. ciscn_2019_n_8 1

    拿到题目老样子先判断是多少位的程序 可以看到是32位的程序,然后再查看开启的保护 然后将程序放入ida进行汇编 先shift+f12查看程序是否有system和binsh 可以看到有system和bi ...

  10. M语言的写、改、删(Power Query 之 M 语言)

    M语言基本上和其他语言一样,用敲键盘的方式写入.修改.删除,这个是废话. M语言可以在[编辑栏]或[高级编辑器]里直接写入.修改.删除,这个也是废话. M语言还有个地方可以写入.修改.删除,就是[自定 ...