安卓开发项目——智能农业

本文介绍了安卓智能农业项目的开发过程,主要包括设置布局、填充数据、使用ViewPager、创建自定义对话框、处理传感器数据以及控制农业设备开关状态。通过OkHttpClient与农业接口交互,动态显示设备状态并提供控制功能。
摘要由CSDN通过智能技术生成

智能农业的开发步骤

   首先需要导一下数据包。
     compile 'com.makeramen:roundedimageview:2.2.1'--让图片变成圆形的效果

    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'

第一步

我们先做三个页面的滑动,用fragment和viewPager来实现。先建一个三个fragment。把HomePageFragment作为首页。

  fragment_help布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="android.coolweather2.com.agriculturedemo.fragment.HelpFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="帮助"
            android:textColor="#6cd545"
            android:textSize="35sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="操作指引"
            android:textSize="25sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#5fb953">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="1、第一条操作指引"
            android:textSize="25sp" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:src="@mipmap/xiangxia" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#5fb953">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="2、第二条操作指引"
            android:textSize="25sp" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:src="@mipmap/xiangxia" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#5fb953">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="3、第三条操作指引"
            android:textSize="25sp" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:src="@mipmap/xiangxia" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#5fb953">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="4、第四条操作指引"
            android:textSize="25sp" />
    </LinearLayout>

</LinearLayout>
fragment_set布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="android.coolweather2.com.agriculturedemo.fragment.SetFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="设置"
            android:textColor="#23a949"
            android:textSize="30sp" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#716c6c" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:src="@mipmap/zidongkongzhi" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="自动控制"
            android:textSize="25sp" />

        <ImageView
            android:layout_width="20dp"
            android:layout_height="40dp"
            android:layout_gravity="right|center_vertical"
            android:layout_marginRight="15dp"
            android:src="@mipmap/gengduo" />


    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#716c6c" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:src="@mipmap/qinchuhuancun" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="清除缓存"
            android:textSize="25sp" />

        <TextView
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:gravity="center"
            android:paddingRight="5dp"
            android:text="660M"
            android:textSize="20sp" />


    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#716c6c" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:src="@mipmap/banbengengx" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="版本更新"
            android:textSize="25sp" />

        <TextView
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:gravity="center"
            android:paddingRight="5dp"
            android:text="V2.0"
            android:textSize="20sp" />


    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#716c6c" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:src="@mipmap/guanyuwomen" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="关于我们"
            android:textSize="25sp" />

        <ImageView
            android:layout_width="20dp"
            android:layout_height="40dp"
            android:layout_gravity="right|center_vertical"
            android:layout_marginRight="15dp"
            android:src="@mipmap/gengduo" />


    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#716c6c" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="15dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:src="@mipmap/my_exit" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="退出登录"
            android:textSize="25sp" />


    </LinearLayout>

</LinearLayout>
fragment_home_page布局:在这里面需要用到ScrollView来进行页面的滚动。我们可以把homepage里面的东西单独拿出来,放在各自的XML文件里面。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="android.coolweather2.com.agriculturedemo.fragment.HomePageFragment">


    <TextView
        android:id="@+id/home_page_top_lin"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_horizontal"
        android:text="智能农业"
        android:textColor="#24bd3b"
        android:textSize="30dp" />


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/mai
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值