Android的banner(轮播图)的实现

本文通过使用ViewPager详细讲解了Android中如何实现轮播图功能,包括布局代码编写、Activity逻辑处理、动态生成指示器以及自定义适配器,特别强调了无限轮播的关键点和注意事项。
摘要由CSDN通过智能技术生成

本文使用了ViewPager来实现轮播图的功能,轮播的图片资源来源于网上。

一、思路

我们想要实现一个轮播图的功能,首先能想到的是使用ViewPager来实现,根据上一篇文章的内容
http://blog.csdn.net/llayjun/article/details/51362905,我们能想到有一个区别如下:

1、就是使得ViewPager实现启动页来无限的轮播图片

2、启动一个定时器来完成自动的轮播效果。

二、写布局代码

1、我们先是来看一下效果图,如何,还是可以的吧。
这里写图片描述
这里写图片描述

注意点:这一节对于上一节,有几处是不相同的。相对于ViewPager来实现启动页
1、上一节的指示器是固定在xml文件中写的,此一节,我们动态来实现。

2、主界面布局准备。
先把布局文件画好。在layout文件中的activity.xml文件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

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

        <TextView
            android:id="@+id/tv_bannertext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="5dp"
            android:text="我是第一个广告语"
            android:textColor="@android:color/white" />

        <LinearLayout
            android:id="@+id/points"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal">


        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

注意

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值