一、需求
1. 主页面实现侧拉效果、导航条效果、分页加载、上拉刷新下拉加载、多条目加载
2. 主页面listview的item点击事件:打开详情界面
3. 详情界面实现viewpager自动轮播,GridView加载视图,listview数据加载
二、实现步骤(分开实现)
项目列表查看:
布局文件展示:
- content_main.xml:(主界面)
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tab"
app:tabGravity="center"
app:tabIndicatorColor="#ff0"
android:background="#000"
app:tabSelectedTextColor="#ff0000"
app:tabTextColor="#aaa"
app:tabMode="scrollable"
app:tabIndicatorHeight="4dp"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager"
/>
- listview.xml:(主界面的列表)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jwenfeng.library.pulltorefresh.PullToRefreshLayout
android:id="@+id/pull"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>
</LinearLayout>
itemone.xml:(多条目加载使用,奇数组显示图片+文字+时间)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_01"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:id="@+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
- itemtwo.xml:(多条目加载使用,偶数组显示图片+图片+图片)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgtwo_01"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
<ImageView
android:id="@+id/imgtwo_02"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
<ImageView
android:id="@+id/imgtwo_03"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="100dp" />
</LinearLayout>
- zidinyi.xml:(item点击进入后使用)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_01"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
- activity_main2.xml:(item点击进入后的页面)
<RelativeLayout 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.myapp.Main2Activity">
<com.bigkoo.convenientbanner.ConvenientBanner
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/convenientBanner"
android:layout_width="match_parent"
android:layout_height="150dp"
app:canLoop="true"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
<GridView