当前位置:网站首页>Android Internet of things application development (smart Park) - picture preview interface
Android Internet of things application development (smart Park) - picture preview interface
2022-06-25 18:06:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
design sketch :
Implementation steps :
1、 First, in the build.gradle Introduce in the file RecycleView
implementation 'com.android.support:recyclerview-v7:28.0.0'When I'm done , There is a synchronization in the upper right corner Sync Now A hint of , Click to synchronize the build , I'm going to modify activity_main.xml Code for
2、 stay activity_main.xml Add... To the layout file 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>Then create a RecyclerView List item layout
<?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、 Then create RecyclerView Data adapter for
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 year 5 month 9 Japan 17 when 14 branch 30 second ", "2019 year 5 month 9 Japan 17 when 15 branch 30 second ", "2019 year 5 month 9 Japan 18 when 30 branch 30 second ", "2019 year 5 month 9 Japan 18 when 40 branch 30 second ", "2019 year 5 month 10 Japan 17 when 14 branch 30 second "};
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;// picture
private TextView time;// Time
public ViewHolder(View v) {
super(v);
image = v.findViewById(R.id.image);
time = v.findViewById(R.id.time);
}
}
}The last set RecyclerView Adapter for
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);
// Create a linear layout manager , Vertical direction
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
//recyclerView Set up the layout manager
recyclerView.setLayoutManager(linearLayoutManager);
MonitorAdapter adapter = new MonitorAdapter();
// add to Android Its own split line
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
// Setup adapter
recyclerView.setAdapter(adapter);
}
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151106.html Link to the original text :https://javaforall.cn
边栏推荐
- 【flutter 页面跳转后退如何刷新?】
- [matlab] curve fitting
- 解析数仓lazyagg查询重写优化
- Garbage collector and memory allocation strategy
- 深度学习网路模型
- SDN system method | 9 Access network
- 哈希竞猜游戏系统开发如何开发?哈希竞猜游戏系统开发应用详情案例及源码
- Huawei cloud gaussdb (for redis) unveiling issue 19: gaussdb (for redis) comprehensive comparison with CODIS
- conda 修改镜像源
- A simple and easy-to-use graph visualization tool developed recently
猜你喜欢

Kotlin of Android cultivation manual - several ways to write a custom view

Acy100 oil fume concentration online monitor for kitchen oil fume emission in catering industry

为什么在变频器场合需要安科瑞的电力有源滤波器?

Why do we need ankeri's active power filter in frequency converter occasions?
![[compilation principle] lexical analysis](/img/b2/8f7dea3944839e27199b28d903d9f0.png)
[compilation principle] lexical analysis

篇4:win10安装MingW64

Optimization of lazyagg query rewriting in parsing data warehouse

Use diskgenius to expand the capacity of system disk C

IVX 启航
![[daily record] - bug encountered during BigDecimal Division](/img/76/efb117986ac319987d4453bf00bec9.png)
[daily record] - bug encountered during BigDecimal Division
随机推荐
启牛的涨乐财付通如何?安全靠谱吗
广发易淘金和指南针哪个更好,更安全一些
Distributed remote management of distribution room environment
Matlab中图形对象属性gca使用
Expressing integers by the sum of consecutive natural numbers
Deep learning network model
中断操作:AbortController学习笔记
How about qiniu's Zhangle TenPay? Is it safe
Idea global search for Chinese characters [easy to understand]
ACY100油烟浓度在线监控仪针对饮食业厨房油烟排放
股票开户怎么办理?证券开户哪家好 办理开户安全吗
一些常用的知识点积累
篇6:CLion:Toolchains are not configured Configure Disable profile
配电室环境的分布式远程管理
OSError: Unable to open file (truncated file: eof = 254803968, sblock->base_addr = 0, stored_eof = 2
CentOS7 安装 Redis 7.0.2
Using QT to make a beautiful login interface box
为什么在变频器场合需要安科瑞的电力有源滤波器?
Vscode / * * generate function comments
Is the actual account opening complicated? Is online account opening safe?