当前位置:网站首页>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
边栏推荐
- 证券公司排名前十手续费最低 办理开户安全吗
- 视频制作素材网站整理
- 启牛的涨乐财付通如何?安全靠谱吗
- [machine learning] case study of college entrance examination prediction based on multiple time series
- Is it safe for a securities company to open an account with the lowest handling fee among the top ten
- Qt使用SQLITE数据库
- How about qiniu's Zhangle TenPay? Is it safe
- 延时函数如何延时
- Time series analysis of data mining [easy to understand]
- 解决nvprof 报错ERR_NVGPUCTRPERM - The user does not have permission to profile on the target device.
猜你喜欢
158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts
使用DiskGenius拓展系统盘C盘的容量
什么是算子?
Centos7 installing redis 7.0.2
揭秘GES超大规模图计算引擎HyG:图切分
Three traversal methods of binary tree (recursive + non recursive) complete code
Garbage collector and memory allocation strategy
微信小程序报错:request:fail url not in domain list
20 provinces and cities announce the road map of the meta universe
Wechat applet reports an error: request:fail URL not in domain list
随机推荐
Recursion and divide and conquer
安装spark + 用命令运行scala相关项目 + crontab定时执行
Acy100 oil fume concentration online monitor for kitchen oil fume emission in catering industry
IVX 启航
new TypeReference用法 fastjson[通俗易懂]
About Equilibrium - Simplified bottleneck model
怎么判断自己是否适合转行软件测试
TLV decoding
Unity technical manual - interference / noise sub module
启牛的涨乐财付通如何?安全靠谱吗
股票开户怎么办理 办理开户安全吗
What is an operator?
Distributed remote management of distribution room environment
卷积操作的本质特性+TextCNN文本分类
VSCode /**生成函数注释
什么是算子?
QT中QString包含“\u0000“的处理方式
User scheduling problem
【 NLP 】 in this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3
Utilisation de diskgenius pour augmenter la capacité du disque système C