Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面
效果图:
自定义对话框布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<!--自定义对话框,线性布局水平方向-->
<!--第一部分标题栏-->
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#257CFF"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="设置阈值"
android:textColor="@android:color/white"
android:textSize="18sp"/>
<!--设置温度阈值-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="温度阈值设置:"
android:textColor="#6C6C6C"/>
<!--设置阈值-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1">
<TextView
android:id="@+id/tv_tempValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="30"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="℃"
/>
</LinearLayout>
<SeekBar
android:id="@+id/sb_temp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:max="60"
android:progress="30"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="数值范围 0-60℃"
android:textColor="#6C6C6C"/>
<!--分割线-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc"></View>
<!--设置湿度阈值-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="湿度阈值设置:"
android:textColor="#6C6C6C"/>
<!--设置阈值-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1">
<TextView
android:id="@+id/tv_humiValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="30"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%RH"
/>
</LinearLayout>
<SeekBar
android:id="@+id/sb_humi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:max="100"
android:progress="30"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="数值范围 0-100%RH"
android:textColor="#6C6C6C"/>
<!--分割线-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc"></View>
<!--设置光照阈值-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="光照阈值设置:"
android:textColor="#6C6C6C"/>
<!--设置阈值-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1">
<TextView
android:id="@+id/tv_lightValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text="3000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lx"/>
</LinearLayout>
<SeekBar
android:id="@+id/sb_light"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:max="10000"
android:progress="3000"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="数值范围 0-10000Lx"
android:textColor="#6C6C6C"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#cccccc"></View>
<!--确定,取消按钮-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="确定"
android:textColor="#257CFF"/>
<!--分割线-->
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#cccccc"></View>
<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="取消"
android:textColor="#257CFF"/>
</LinearLayout>
</LinearLayout>
自定义对话框实现类:
package com.newland.project3_3;
import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
/**
* 设置阈值对话框
*/
public class SettingThresholdDialog extends Dialog {
private TextView tvTempValue,tvHumiValue,tvLightValue;
private Button btnCancel;
private Button btnConfirm;
private SeekBar sbTemp,sbHumi,sbLight;
public SettingThresholdDialog(@NonNull Context context) {
super(context,R.style.Dialog);
//关联布局文件
this.setContentView(R.layout.dialog_setting_threshold);
//初始化组件
initView();
addListener();
}
private void initView() {
sbTemp = findViewById(R.id.sb_temp);
sbHumi = findViewById(R.id.sb_humi);
sbLight = findViewById(R.id.sb_light);
tvTempValue = findViewById(R.id.tv_tempValue);
tvHumiValue = findViewById(R.id.tv_humiValue);
tvLightValue = findViewById(R.id.tv_lightValue);
btnCancel = findViewById(R.id.btn_cancel);
btnConfirm = findViewById(R.id.btn_confirm);
}
private void addListener() {
//温度SeekBar状态改变监听
sbTemp.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//SeekBar进度显示到TextView上
tvTempValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//湿度SeekBar状态改变监听
sbHumi.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//SeekBar进度显示到TextView上
tvHumiValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//光照SeekBar状态改变监听
sbLight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//SeekBar进度显示到TextView上
tvLightValue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//设置确定点击事件
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//对话框消失
SettingThresholdDialog.this.dismiss();
}
});
//设置取消点击事件
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//对话框消失
SettingThresholdDialog.this.dismiss();
}
});
}
}
在主类中创建对话框并显示:
package com.newland.project3_3;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//创建对话框并显示
SettingThresholdDialog dialog = new SettingThresholdDialog(this);
dialog.show();
}
}
Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面的更多相关文章
- Android物联网应用程序开发(智慧园区)—— 图片预览界面
效果图: 实现步骤: 1.首先在 build.gradle 文件中引入 RecycleView implementation 'com.android.support:recyclerview-v7: ...
- Android物联网应用程序开发(智慧城市)—— 环境状态值范围设置界面开发
效果图: 代码: 布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...
- Android物联网应用程序开发(智慧园区)—— 园区监控系统界面
效果图: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- Android物联网应用程序开发(智慧园区)—— 登录界面开发
效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- Android物联网应用程序开发(智慧城市)—— 查询购物信息界面开发
效果: 布局代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xm ...
- Android物联网应用程序开发(智慧城市)—— 用户注册界面开发
效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...
- Android物联网应用程序开发(智慧城市)—— 摄像头监控界面开发
效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...
- Android物联网应用程序开发(智慧城市)—— 火焰监控界面开发
效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns: ...
- Android物联网应用程序开发(智慧城市)—— 购物信息的存储界面开发
效果: 布局代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
随机推荐
- SpringBoot-RestTemplate测试Controller
1.功能测试类 package com.imooc.controller; import java.io.IOException; import java.math.BigDecimal; impor ...
- SVN的基本介绍\服务器配置
### 1. 工作场景 1. 进入公司需要做的关于开发的第一件事, 就是向项目经理索要SVN服务器地址+用户名+密码### 2. 角色解释> 服务器: 用于存放所有版本的代码,供客户端上传下载更 ...
- 关于requests.exceptions.ConnectionError: HTTPSConnectionPool的问题
错误如下: raise ConnectionError(e, request=request)requests.exceptions.ConnectionError: HTTPSConnectionP ...
- 【C/C++】链表
#include <bits/stdc++.h> using namespace std; struct node { int data; // 数据 node* next; // 指针 ...
- 【C/C++】two pointers/归并排序/原理/理解/实现/算法笔记4.6
1.two pointers 思路:对序列进行扫描的时候,根据序列本身的特性用两个下标i和j对序列进行扫描,从而降低算法复杂度. ·例1 在递增序列中找a + b = M while (i<j) ...
- MySQL记录锁、间隙锁、临键锁小案例演示
生成间隙(gap)锁.临键(next-key)锁的前提条件 是在 RR 隔离级别下. 有关Mysql记录锁.间隙(gap)锁.临键锁(next-key)锁的一些理论知识之前有写过,详细内容可以看这篇文 ...
- pipeline 共享库
目录 一.简介 二.共享库扩展 共享库使用 共享库结构 pipeline模板 一些小问题 三.共享库例子 使用公共变量 使用共享库的src方法 使用共享库的vars方法 四.插件实现pipeline ...
- 统计函数(Excel函数集团)
此处文章均为本妖原创,供下载.学习.探讨! 文章下载源是Office365国内版1Driver,如有链接问题请联系我. 请勿用于商业! 谢谢 下载地址:https://officecommunity- ...
- 文本处理的命令,三剑客之sed
文本处理的命令 1.sort命令 "用于将文件内容加以排序" 参数: -n :按照数值的大小排序 -r :以相反的顺序来排序 -k :以某列进行排序 -t :指定分隔符,默认是以空 ...
- CF742B Arpa's obvious problem and Mehrdad's terrible solution 题解
Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示 ...