Android ViewPager 无限滚动广告栏

现在很多App在进入的时候,都会在首页的顶部有一个广告栏,具体实现了以下的功能:

1.实现用户左右手动滑动

2.实现广告栏自动轮播

3.实现广告栏点击事件

4.无论是用户手动滑动还是广告栏自动轮播的时候,下方的指示点都会随之改变状态

5.实现用户点击或者拖拽时轮播停止,松手时继续轮播

先上3个效果gif吧:

第一个gif,展示的是功能1和2;

第二个gif,展示的是功能3;

第三个gif展示的是功能5;

那功能4,每个gif都可以看得到。

以上就是所有的效果,那么以下部分,是代码逻辑,我们一部分一部分粘贴出来,很多地方都已经写了非常详细的注释了:

先上布局文件,布局文件就非常简单,activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.honey.guanggaoview.MainActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="180dp"></android.support.v4.view.ViewPager>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/vp"
        android:background="#44000000"
        android:orientation="vertical"
        android:padding="5dp">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

        <LinearLayout
            android:id="@+id/point_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
       
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值