前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ViewFlipper实现上下翻滚轮播效果

ViewFlipper实现上下翻滚轮播效果

作者头像
砸漏
发布2020-10-16 11:15:39
1.6K0
发布2020-10-16 11:15:39
举报
文章被收录于专栏:恩蓝脚本

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

(1).MainActivity.java:

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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:(动画资源文件)

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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 

以上就是本文的全部内容,希望对大家的学习有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档