首页 > 其他分享 >Android ViewPage2 引导页动画

Android ViewPage2 引导页动画

时间:2023-04-04 09:25:40浏览次数:37  
标签:动画 indicator ViewPage2 imgList 选中 Android 小圆点 id

使用ViewPage2模拟引导页动画的效果

首先我们需要自定义出我们需要的形状未选择状态  indicator_off.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size android:width="8dp" android:height="8dp"></size>
    <solid android:color="#cccccc"/>

</shape>

 

 

自定义设置选中时的文件 indicator_in.xml   这里我们设置的长一点模拟滑动粘连效果

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size
        android:width="12dp"
        android:height="8dp"></size>
    <corners android:radius="8dp" />
    <solid android:color="@color/mycolor" />

</shape>

 

 

 

 

 

 

我们将使用相对布局,把我们需要进行提示的小圆点放到ViewPage2 的控件上

效果如图所示

 

布局文件代码

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".FirstActivity">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/vp_splash"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dp"
        android:foregroundGravity="center"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/img1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"
            android:src="@drawable/indicator_off" />

        <ImageView
            android:id="@+id/img2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"

            android:src="@drawable/indicator_off" />

        <ImageView
            android:id="@+id/img3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"

            android:src="@drawable/indicator_off" />
    </LinearLayout>
</RelativeLayout>

代码部分  给ViewPage2控件添加监听 判断是否选中状态 更改小圆点文件

            List<Integer> imgList = new ArrayList<Integer>();//添加我们定义的小圆点
            imgList.add(R.id.img1);//之前布局文件设置的图像视图
imgList.add(R.id.img2); imgList.add(R.id.img3); vpSplash.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override //int索引 public void onPageSelected(int position) { super.onPageSelected(position); //5、for循环遍历列表 for (int i = 0; i < imgList.size(); i++) { //3、获取图片框 ImageView imageView = (ImageView) findViewById(imgList.get(i)); //判断是否被选中蓝点 if (i == position) { //被选中显示蓝点 imageView.setImageResource(R.drawable.indicator_in); } else { //未选中显示灰点 imageView.setImageResource(R.drawable.indicator_off); } } } });

 

标签:动画,indicator,ViewPage2,imgList,选中,Android,小圆点,id
From: https://www.cnblogs.com/mdlztjk/p/17285251.html

相关文章

  • Android studio 常用快捷键
    Ctrl+D:集合了复制和粘贴两个操作,如果有选中的部分就复制选中的部分,并在选中部分的后面粘贴出来,如果没有选中的部分,就复制光标所在的行,并在此行的下面粘贴出来。Ctrl+O:子类想重写父类的方法时,按此组合键可显示所有父类的方法。接口对应的组合键时Ctrl+I。Ctrl+Alt+L格式化代......
  • Android中的persistent属性
    在我们开发系统级的App时,很有可能就会用到persistent属性。当在AndroidManifest.xml中将persistent属性设置为true时,那么该App就会具有如下两个特性:在系统刚起来的时候,该App也会被启动起来该App被强制杀掉后,系统会重启该App。这种情况只针对系统内置的App,第三方安装的App不......
  • android点击按钮弹出复选框
    String[]items={"餐饮","出行","娱乐","学习","日用品","其他"};Stringconsumetype="";List<String>mytypes=newArrayList<>();AlertDialog.Builderbuilder=newAlertDialog.Builder(addmes......
  • android 评分条 RatingBar 使用及自定义
    一、先上效果图片:  第一个是自定义;  第二个是原生的: 二、atingBarRatingBar是基于SeekBar和ProgressBar的扩展,用星型来显示等级评定。使用RatingBar的默认大小时,用户可以触摸/拖动或使用键来设置评分,它有两种样式(小风格用ratingBarStyleSmall,大风格用ratingBarStyleIndica......
  • android 调用地图
    有时候我们需要调用地图显示一下位置,这时候可能还需要导航,导航做起来有点麻烦,如果调用第三方的是不是很简单,本文就是写这个来的;第一种方式:androidIntent调用地图应用客户端调用百度地图:百度地图包:com.baidu.BaiduMaptry{intent=Intent.getIntent("intent://m......
  • <Android> ListView 列表控件的使用-李国庆-专题视频课程
    ListView列表控件的使用—15573人已学习课程介绍        1,ListView介绍;2,原理讲解;3,简单实现;4,ListView扩展;课程收益    通过学习本课程,具有一定的Android开发技能和知识,熟练掌握这一专题中集成组件与布局属性、实现listview基本用法,及简单扩展。讲师介绍    ......
  • android下拉菜单 spinner 学习
    首先看一下继承关系:publicclassSpinnerextendsAbsSpinnerimplementsDialogInterface.OnClickListenerClassOverview视图在同一时间只能显示一个子项,用户通过下拉的方式可以选择其中的一种项。该子项在Spinner来自来Adpater视图适配器。首先看一下效果图:Spinner控件的使......
  • android 解决ScrollView嵌套ListView的问题,不能全屏,全屏不能显示下面控件
    在开发中遇到ScrollView嵌套ListView的问题,最开始发出不能全屏,效果是这样的;但我想要的效果是这样的:下面看一下布局文件:<?xmlversion="1.0"encoding="utf-8"?><ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_p......
  • Android 在程序中动态添加 View 布局或控件
    有时我们需要在程序中动态添加布局或控件等,下面用程序来展示一下相应的方法:1、addView添加View到布局容器2、removeView在布局容器中删掉已有的View3、LayoutParams 设置View的大小位置下面来看一个demo;publicclassMainActivityextendsActivity{ @Override protectedvo......
  • Android ImageView 详述
    结构继承关系publicclassView.OnClickListnerextendsView java.lang.Objectandroid.view.Viewandroid.widget.ImageView类概述显示任意图像,例如图标。ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各......