Android物联网应用程序开发(智慧园区)—— 图片预览界面

添加完成后,在右上角有一个同步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>

接着创建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” />

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);

资源分享

一线互联网面试专题

379页的Android进阶知识大全

379页的Android进阶知识大全

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

2020年虽然路途坎坷,都在说Android要没落,但是,不要慌,做自己的计划,学自己的习,竞争无处不在,每个行业都是如此。相信自己,没有做不到的,只有想不到的。祝大家2021年万事大吉。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!
术体系对大家有一个方向参考。

2020年虽然路途坎坷,都在说Android要没落,但是,不要慌,做自己的计划,学自己的习,竞争无处不在,每个行业都是如此。相信自己,没有做不到的,只有想不到的。祝大家2021年万事大吉。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

  • 26
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值