思路:
黑白简约风,传感器以黑白风的家居图片为底,展示设备数据,每个模块右边和下面都有2.66dp的黑色描边体现阴影
图片圆角效果
使用控件:
androidx.cardview.widget.CardView
ImageView
LinearLayout
通过设置CardView本身圆角达到然后把控件放入达到图片圆角的效果
代码示例:
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:cardCornerRadius="15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/temp_beijing" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="81dp"
android:layout_weight="20">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#C4000000"
android:gravity="bottom|center"
android:orientation="vertical">
<TextView
android:id="@+id/t_temp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="10℃"
android:textColor="#FFFFFF"
android:textSize="30dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#C4000000"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="室内温度"
android:textColor="#D6C9C9"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
设置xml半边阴影加圆角效果
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 第一层 上部和左部偏移一定距离-->
<item
android:left="2.66dp"
android:top="2.66dp">
<shape>
<solid android:color="#D6C7C7" />
<corners android:radius="20dp"/>
<!-- 描边 -->
<stroke
android:width="3dp"
android:color="#A59A9A"/>
</shape>
</item>
<!-- 第二层 下部和有部偏移一定距离-->
<item
android:bottom="2.66dp"
android:right="2.66dp">
<shape>
<gradient
android:angle="135"
android:startColor="#FFFFFF"
android:centerColor="@color/white"
android:endColor="#ACA9A9"
/>
<corners android:radius="20dp"/>
<!-- 描边 -->
<stroke android:width="0.33dp"
android:color="#dedede" />
</shape>
</item>
</layer-list>
ScrollView下拉控件
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 你需要下拉的东西 -->
</ScrollView>
后端功能
基本的采集控制
一个按钮完成开关报警灯切不冲突,策略默认开启
当我们手动打开报警的时,关闭策略,关闭报警的策略开启,不冲突
当策略自动打开报警灯时,我们手动关闭,关闭策略,手动和自动不冲突
if (smoke_celue){ // 打开策略控制报警灯
if(Objects.equals(Smoke, "1")){
ala_onoff = true;
text_smoke.setText("异常");
text_smoke.setTextColor(0xFFFF0000);
text_ala.setBackgroundResource(R.drawable.ala_on);
txt_ala.setTextColor(0xFFFFFFFF);
l_ala.setBackgroundResource(R.drawable.black_card);
control("m_alarmlight",1);
}else{
ala_onoff = false;
text_smoke.setText("正常");
text_smoke.setTextColor(0xFFFFFFFF);
text_ala.setBackgroundResource(R.drawable.ala_off);
txt_ala.setTextColor(0xFF000000);
l_ala.setBackgroundResource(R.drawable.control_card);
control("m_alarmlight",1);
}
s_ala.setChecked(ala_onoff);
}else {//关闭策略不控制报警灯,只控有害气体浓度是否正常
if(Objects.equals(Smoke, "1")){
ala_onoff = true;
text_smoke.setText("异常");
text_smoke.setTextColor(0xFFFF0000);
}else{
ala_onoff = false;
text_smoke.setText("正常");
text_smoke.setTextColor(0xFFFFFFFF);
}
}