智能农业的开发步骤
首先需要导一下数据包。
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