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 ...
随机推荐
- 生产环境高可用centos7 安装配置RocketMQ-双主双从-同步双写(2m-2s-sync)
添加hosts信息[四台机器] vim /etc/hosts 192.168.119.130 rocketmq-nameserver1 192.168.119.130 rocketmq-master1 ...
- listView 多布局
最近在开发项目中遇到了实现类似淘宝首页的需求,使用listView可以解决,在此记录一下. 实现步骤: 重写 getViewTypeCount() – 返回你有多少个不同的布局 重写 getItemV ...
- ehcache详解
Ehcache是现在最流行的纯Java开 源缓存框架,配置简单.结构清晰.功能强大,最初知道它,是从Hibernate的缓存开始的.网上中文的EhCache材料以简单介绍和配置方法居多, 如果你有这方 ...
- ORACLE DBMS_ROWID包详解
这个包在11gR2中有11个函数或存储: 1. 根据给定参数返回一个rowid --根据给定参数返回一个rowid FUNCTION rowid_create(rowid_type IN NUMBER ...
- ORACLE CACHE BUFFER CHAINS原理
原理图如下: 一个cache buffer chains 管理多个hash bucket,受隐含参数:_db_block_hash_buckets(控制管理几个hash bucket)
- SpringBoot java配置类@Configuration 的两种写法
首先在Springboot项目中,件一个java类,使用注解@Configuration ,则这个类是SpringBoot bean的创建的配置文件类,,这种配置文件类有两种写法 1.使用包扫描 , ...
- VUE页面实现加载外部HTML方法
前后端分离,后端提供了接口.但有一部分数据,比较产品说明文件,是存在其他的服务器上的.所以,在页面显示的时候,如果以页面内嵌的形式显示这个说明文件.需要搞点事情以达到想要的效果.本文主要和大家介绍VU ...
- 3.0 go mod之远程仓库搭建-代码示例
注意事项 所谓的远程仓库指的是github,个人首次使用go mod在其他云仓库上尝试,并未成功,这浪费了我近2小时的时间: 如果你是初次尝试,那么除了github的地址换一下之外,其他的都按照示例操 ...
- 【Spring Framework】Spring入门教程(四)注册Bean到IOC容器
注册Bean到IOC容器大致分为4种: ①.包扫描+组件注解(@Controller.@Service.@Repository.@Component) 针对类是我们自己编写的情况 ②.@Bean注解 ...
- Tableau如何绘制瀑布图
一.将子类别拖至列,利润拖拽至行,类型改为甘特条形图 二 右键利润-快速表计算-汇总(数据会从左向右显示累计汇总) 三.创建计算字段-[利润] 四.将负利润拖拽到大小,利润拖拽到颜色 分析-合计-显示 ...