展会信息港展会大全

Android ViewFlipper Animation
来源:互联网   发布日期:2016-01-14 11:24:49   浏览:1494次  

导读:[功能]1、Android ViewFlipper可以包含多个View且View之间的切换有Animation,比如:渐变效果。[代码]1、创建包含ViewFlipper的main.xml还包含2个Button用于各个View的切换。?xml version=1.0 encoding=u......

[功能]

1、Android ViewFlipper可以包含多个View且View之间的切换有Animation,比如:渐变效果。

[代码]

1、创建包含ViewFlipper的main.xml还包含2个Button用于各个View的切换。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button

android:id="@+id/previousButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Previous" />

<Button

android:id="@+id/nextButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Next" />

</LinearLayout>

<ViewFlipper

android:id="@+id/flipper"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:gravity="center">

</ViewFlipper>

</LinearLayout>

2、设定Animation效果

flipper = (ViewFlipper) findViewById(R.id.flipper);

flipper.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));

flipper.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));

3、在ViewFlipper里面增加各种View

flipper.addView(addTextByText("HelloAndroid"));

flipper.addView(addImageById(R.drawable.beijing_003_mb5ucom));

flipper.addView(addTextByText("eoe.Android"));

flipper.addView(addImageById(R.drawable.beijing_004_mb5ucom));

flipper.addView(addTextByText("Gryphone"));

ublic View addTextByText(String text){

TextView tv = new TextView(this);

tv.setText(text);

tv.setGravity(1);

return tv;

}

public View addImageById(int id){

ImageView iv = new ImageView(this);

iv.setImageResource(id);

return iv;

}

4、View切换

* 下一个View

flipper.showNext();

* 上一个View

flipper.showPrevious();

赞助本站

人工智能实验室

相关热词: ViewFlipper Animation

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港