服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - ViewFlipper实现上下翻滚轮播效果

ViewFlipper实现上下翻滚轮播效果

2022-10-28 13:47猴菇同学 Android

这篇文章主要为大家详细介绍了ViewFlipper实现上下翻滚轮播效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

一种可以设置滑动动画的控件,只显示一行布局,在布局文件中的ViewFlipper控件中顺序写好每一行的布局

(1).MainActivity.java:

?
1
2
3
4
5
6
ViewFlipper mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper));
mFlipper.startFlipping();
// 设置进入动画
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
// 设置滚出动画
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));

(2).activity_main.xml:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<ViewFlipper
  android:id="@+id/flipper"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginBottom="20dip"
  android:flipInterval="3000" > // 设置滑动间隔时间(毫秒)
 
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/animation_2_text_1"
    android:textSize="26sp" />
 
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/animation_2_text_2"
    android:textSize="26sp" />
 
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/animation_2_text_3"
    android:textSize="26sp" />
</ViewFlipper>

(3).push_up_in.xml:(动画资源文件)

?
1
2
3
4
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="300"/>
  <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>

push_up_out.xml:

?
1
2
3
4
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="300"/>
  <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq_31715429/article/details/50972357

延伸 · 阅读

精彩推荐