Animation in Viewpager tab change fadein / fadeout as like Linkedin introduction screen(Viewpager 选项卡中的动画更改淡入/淡出,就像 Linkedin 介绍屏幕一样)
问题描述
我想为它的介绍(登录/注册)屏幕实现相同类型的动画,例如在 android 应用程序中的链接.
I want to implement same kind of animation such as linked in does in android application for its Introduction(Login / register) screen.
我正在为介绍屏幕使用视图寻呼机,我想在背景图像更改时实现淡入淡出动画,根据从右向左滑动,反之亦然.我想根据屏幕的滑动实现背景图像变化的淡入淡出动画.任何帮助表示赞赏.请看我的布局代码
I am using view pager for Introduction screen and i want to implement fadein fadeout animation on background image change, As per swipe right to left or vice versa. I want to implement fadein and fadeout animation on background image change according to swipe of screen. any help is appreciated. Please take a look at my layout code
而View pager片段布局是
And View pager fragment layout is
示例 Splashs creen 这是我想要实现的.谢谢
sample Splashs creen this is what i want to implement. Thank you
推荐答案
这是一个 lag free
并且还处理 Buttons
This is a lag free
one and also handles the Buttons
主要思想:
1) 首先为您的片段创建透明背景.
1) first create transparent background for your fragments.
2) 创建 LayerDrawable
并将每个片段的背景图像添加为一个项目.然后添加你的 LayerDrawable
作为你的 viewpager 的背景.
2) Create LayerDrawable
and add background image of each fragment as an item. Then add your LayerDrawable
as a background of your viewpager.
3) 在 onCreate
方法中正确设置每一层的 alpha,因此只有上一层的 alpha 值为 255.
3) in onCreate
method set alpha of each layer correctly so just upper one has alpha value of 255.
4) 为您的 FragmentStatPagerAdapter
的每个视图设置一个标签,该标签对应于您在 LayerDrawable
中声明的可绘制索引.例如,当您打开应用程序 FragmentA
时,它的标签必须对应于 2 的上部可绘制对象(从 0 开始).最后一页标签必须为 0 对应于最低可绘制对象.
4) set for each view of your FragmentStatPagerAdapter
a tag that corresponds to drawable index that you declared in the LayerDrawable
. for example when you open the app FragmentA
is showing so its tag must correspond to upper drawable that is 2 (beginning from 0). last page tag must be 0 corresponds to lowest drawable.
5) 在transformPage
6) 添加按钮使用RelativeLayout
.为了在所有视图上放置按钮,请使用 RelativeLayout
.后来的孩子在 Z 轴上的位置更高.可以在代码中看到:
6) for adding the button use RelativeLayout
.
In order to place buttons on top of all views use RelativeLayout
. Later children are placing higher on the Z axis. You can see it in the code:
现在让我们看看代码:
主活动
activity_main.xml
activity_main.xml
LayerDrawable
LayerDrawable
对于不想声明片段的懒人:
for lazy people who just do not want to declare fragments:
片段A
fragment_a.xml
fragment_a.xml
这篇关于Viewpager 选项卡中的动画更改淡入/淡出,就像 Linkedin 介绍屏幕一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!