一、需求
在一个页面顶部展示多图,横向轮播,也即是通俗意义的Banner。需求细节解析:
1,同一个位置,展示不同的内容,包含展示图片、标题、内容描述【内容切换】;
2,因为同一个位置展示,需要有标示,告知用户当前所在的位置;【位置标识】;
3,便于内容的全部展示且不拒绝用户的主动操作,需要自动轮播与手动滑动处理相结合;【手动自动】;
4,当前位置内容可变,需要兼容多种模式【特值处理】;
二、实现思路
实现功能,一般通过现有控件,加以事件控制而达到目标。在基本实现上,可以通过抽取组合,形成自定控件。
基本实现:
1,选择ViewPager,基本已兼容大部分功能;
2,制作定位标志,标识当前所处位置;
3,再实现定时任务,达到各个页面的自动切换;
三、具体实现
1,xml文件
<FrameLayout
android:layout_width="match_parent"
android:layout_height="210dp">
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="210dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@mipmap/shadow_article">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/author_layout"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:maxLines="2"
android:text="标题"
android:textColor="@color/white"
android:textSize="18sp" />
<RelativeLayout
android:id="@+id/author_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft