前言:智能农业这个项目可以说是大多都是我们自己完成的。是对于前一个多月Android学习的一个检验,同时也是对我们成绩的一个凭据。意义非常重大。
一、对于布局方面
下面我放两张例图,是我认为在布局上对我有难度的点
可以看到页面最下方的分别是首页,设置和帮助。而各自的页面上又有各自的内容,所以我们就要用到Fragment和ViewPager现结合,来实现页面的滑动和点击翻页。(由于布局很多,我就挑着些重要的说)
1.首先定义一个Activity类来写页面下方的主页,设置和帮助。这是在三个页面固定不动的。
<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"
android:orientation="vertical"
tools:context="com.example.myapplication15.classActivity">
<android.support.v4.view.ViewPager
android:id="@+id/class_viewpager"
android:layout_width="match_parent"
android:layout_height="570dp">
</android.support.v4.view.ViewPager>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/class_viewpager"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/main_ll"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/b1"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="首页"
android:textSize="15sp"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:id="@+id/set_ll"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/b2"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置"
android:textSize="15sp"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:id="@+id/help_ll"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/b3"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="帮助"
android:textSize="15sp"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
2.接下来就是上面三个Fragment页面用使用Fragment和ViewPager来实现页面的滑动和点击翻页,在这里面我们就是要对布局页面进行填充了。(我用首页来举例)
- 在布局文件里对首页的进行代码编程
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myapplication15.fragment.MainFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:text="智能农业"
android:textColor="#28c014"
android:textSize="30sp" />
<android.support.v4.view.ViewPager
android:id="@+id/title_pic_viewpager"
android:layout_width="match_parent"
android:layout_height="150dp">
</android.support.v4.view.ViewPager>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout