Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面

Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面效果图:自定义对话框布局:<?xmlversion=”1.0″encoding=”utf-8″?><LinearLayoutxmlns:android=”http://schemas.android.com/apk/res/android”android:layout_width=”350dp”android:layout_height=”wrap_content”andro

大家好,又见面了,我是你们的朋友全栈君。

效果图:

Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面

自定义对话框布局:

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

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151784.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • CANoe/CANalyzer诊断功能的深入理解以及CAPL诊断编程实现

    CANoe/CANalyzer诊断功能的深入理解以及CAPL诊断编程实现之前和大家分享了CANoe的基础使用(分析、仿真、测试、诊断),这篇文章将继续深入探讨如何使用CANoe/CANalyzer中的诊断功能。诊断用于在将ECU安装到系统之前或之后配置,维护,支持,控制和扩展ECU,例如,一辆车。诊断通常在请求-响应方案中执行:测试仪(客户端)向…

    2022年6月30日
    32
  • 企业微信提现到个人银行卡_微信支付怎么把钱提出来

    企业微信提现到个人银行卡_微信支付怎么把钱提出来https://blog.csdn.net/baidu_37366055/article/details/81215962?utm_source=blogxgwz7后续需要使用,所以暂时转载记录一下

    2022年8月19日
    2
  • 尝试HTML + JavaScript 编写Windows App

    尝试HTML + JavaScript 编写Windows App

    2022年3月12日
    45
  • 阿里,B站小伙伴刚刚分享的大数据开发运维学习规划,抓紧收藏

    一.大数据运维与架构课程体系1.0课程与老师介绍本课程是专门培养大数据运维与架构方向专业人才的体系化课程。课程所有讲师小伙伴全部是在职的知名企业大数据开发专家,大数据技术专家职位员工,非专门的培训机构老师(小伙伴当前在职企业阿里巴巴,哔哩哔哩,平安集团,苏宁易购,美团等,运维集群规模大到10000+节点,课程内容可以满足市面上80%以上企业的大数据运维工作)。课程以企业大数据集群运维实战和招聘需求为出发点,深入浅出,有重点地为大家系统化地讲解整个大数据运维需要的知识点,实战教学,多年运维经验分享

    2022年4月17日
    47
  • linux 卸载cuda_如何卸载CUDA

    linux 卸载cuda_如何卸载CUDALinux下cuda卸载亲测好用#1.用runfile方式安装的删除方法:sudo/usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl#2.用packagemanager方式安装的删除方法:sudoapt-get–purgeremovecuda-8.0sudoaptautoremovesudoapt-getautoclean#cudnn文件和samples残留在/usr/local/cuda-8.0/,删除

    2022年9月6日
    5
  • Kettle详细使用教程

    Kettle详细使用教程Kettle详细使用教程文章内容链接Kettle插入更新、自定义常量数据与删除、增加常量、增加序列Kettle插入更新、自定义常量数据与删除、增加常量、增加序列Kettle字段选择、剪切字符串、字符串替换、Concatfields、字符串操作Kettle字段选择、剪切字符串、字符串替换、Concatfields、字符串操作Kettle排序记录、去除重复记录、拆分字段、值映射、替换NULL值Kettle排序记录、去除重复记录、拆分字段、值映射、替换NULL值

    2022年5月10日
    54

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号