android导航点自动生成,Android史上最简单的引导页导航点实现方式【原创】

这几天在学习Android程序启动页加引导页以及导航点的实现,我们可以通过ViewPager来实现整个过程,下面我们来看看传统的方法实现的过程,然后通过与“Android史上最简单的引导页导航点实现方式”对比一下,可以发现代码量以及复杂程度都大大的减轻了呢。

1.传统方式实现:首先导航点的实现我们需要到github上面去下载相应的依赖库,来完成我们需要的效果。如下:ViewPager-300x279.png

这里我们就用CirclePageIndicator小圆点来实现导航点的效果。

Activity主布局文件:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/id_viewpager"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/white" />

android:id="@+id/indicator"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_marginBottom="8dp"

android:padding="10dp" />

然后就是引导页的三个布局,这里只展示一个就行了,因为几乎都是一样的。

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@mipmap/bg_boot_page_one"/>

接下来就是我们的activity的文件了

import android.app.Activity;

import android.os.Bundle;

import android.support.v4.view.ViewPager;

import android.view.LayoutInflater;

import android.view.View;

import com.viewpagerindicator.CirclePageIndicator;

import java.util.ArrayList;

import java.util.List;

import Adapter.ViewPagerAdapter;

public class ViewPagerActivity extends Activity{

private CirclePageIndicator circlePageIndicator;

ViewPager viewPager;

ViewPagerAdapter mpagerAdapter;

private List views= new ArrayList();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_viewpager);

viewPager= (ViewPager) findViewById(R.id.id_viewpager);

circlePageIndicator= (CirclePageIndicator) findViewById(R.id.indicator);

LayoutInflater minflater=LayoutInflater.from(this);

View view02=minflater.inflate(R.layout.viewpager02,null);

View view03=minflater.inflate(R.layout.viewpager03,null);

View view04=minflater.inflate(R.layout.viewpager04,null);

views.add(view02);

views.add(view03);

views.add(view04);

mpagerAdapter=new ViewPagerAdapter(views);

viewPager.setAdapter(mpagerAdapter);

circlePageIndicator.setViewPager(viewPager);

}

}

效果就不展示了,大家在APP启动程序中都见过,下面来见证我们的史上最简单的引导页导航点实现方式。

说白了,就是把导航点和引导页合二为一,我展示一张图片大家就全明白了。

1-169x300.png

2-169x300.png

然后主布局文件就变成了这样

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/id_viewpager"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/white" />

其他的文件就不用我写了吧,因为只要一点点的变动即可。

看到了吧,导航点本身就是图片的一部分,这样做起来其实效果是差不多的,也可以实现对我们的引导页进行导航的一个效果,不用下载什么依赖库也不用在布局文件和activity里写那么多代码了,是不是很简单呢。

转载时请注明出处及相应链接,本文永久地址:https://blog.yayuanzi.com/14129.html

75d087ef9a9fb11dc373caaf33adbf7f.png

微信打赏

支付宝打赏

感谢您对作者Joy的打赏,我们会更加努力!    如果您想成为作者,请点我

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值