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

 

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • vue取消eslint规范_eslint vue

    vue取消eslint规范_eslint vue新手在学习做vue项目的时候老是遇到一些eslint语法错误的情况,比如下面这种情况:error’xxx’isassignedavaluebutneverusedno-unused-vars其实就是有变量创建了未被引用而已。就这样一个问题就会导致程序无法正常运行,所以很麻烦,现介绍关闭eslint语法校验的方法。在项目目录下找到vue.config.js,如果没有就自己新建一个,在里面添加几个配置项,然后重启项目(npmrunserve)就好了module.exports

  • python turtle 表白_pythonturtle背景颜色

    python turtle 表白_pythonturtle背景颜色python中用turtle画爱心表白运行后的效果图:下面的代码是在python3.7写的,代码有点长,但却语法简单易懂代码如下:importturtlestr=input(‘请输入表白语:’)turtle.speed(10)#画笔速度turtle.setup(1800,700,70,70)turtle.color(‘black’,’pink’)#画笔颜色t…

  • 【已解决】【V1.0版本】如何彻底关闭Win10的自动更新并且随时可以恢复?

    【已解决】【V1.0版本】如何彻底关闭Win10的自动更新并且随时可以恢复?更新失败的问题我已经参考这篇文章解决了:【亲测管用】Windows10无法完成更新,正在撤销更改怎么办?精简脚本,在不删除服务的情况下阻止自动更新:【亲测管用】如何使用脚本关闭Win10自动更新服务并阻止其自动启动?如何关闭Windows10的自动更新真的是个大难题.当你遇到Windows更新包安装失败,却又被强制每天重新安装并且失败(安装失败有的时候得重启好几次),望着一遍又一…

  • QueryInterface函数

    QueryInterface函数《COM技术内幕》§3——QueryInterface函数§3——IUnknown.CPP代码清单:////IUnkown.cpp//// #include#include voidtrace(constchar*msg){cout //InterfaceinterfaceIX:IUnknown

  • jQuery点击图片弹出放大特效下载

    效果体验:http://hovertree.com/texiao/jqimg/1/效果图:代码如下:源码下载:http://hovertree.com/h/bjaf/ljn1fwka.htm转自:

    2021年12月22日
  • Qt中操作SQLite数据库

    Qt中操作SQLite数据库0.前言SQLite是一款开源、轻量级、跨平台的数据库,无需server,无需安装和管理配置。它的设计目标是嵌入式的,所以很适合小型应用,也是Qt应用开发种常用的一种数据库。1.驱动QtSQL模块使用驱动程序插件(plugins)与不同的数据库API进行通信。由于Qt的SQL模块API与数据库无关,因此所有特定于数据库的代码都包含在这些驱动程序中。Qt提供了几个驱动程序,也可以添加其他驱动程序。提供驱动程序源代码,可用作编写自己的驱动程序的模型。QtCreator在*.pro中引入sq

发表回复

您的电子邮箱地址不会被公开。

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