2003-view-Animation-push

介绍ViewFlipper

ViewFlipper

Simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval

主要介绍了四中显示方式:

1.由下到上进入消失

2.有右到左进入消失

3.渐变进入消失

4.在三维上进行动画

Animation2.java

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.apis.view;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import com.example.android.apis.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.ViewFlipper;

public class Animation2 extends Activity implements
        AdapterView.OnItemSelectedListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.animation_2);

        mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper));
        mFlipper.startFlipping();

        Spinner s = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, mStrings);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        s.setAdapter(adapter);
        s.setOnItemSelectedListener(this);
    }

    public void onItemSelected(AdapterView parent, View v, int position, long id) {
        switch (position) {

        case 0:
        	//由下到上进入消失
            mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_up_in));
            mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_up_out));
            break;
        case 1:
        	//有右到左进入消失
            mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_left_in));
            mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_left_out));
            break;
        case 2:
        	//渐变进入消失
            mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    android.R.anim.fade_in));
            mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    android.R.anim.fade_out));
            break;
        default:
        	//在三维上进行动画
            mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.hyperspace_in));
            mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.hyperspace_out));
            break;
        }
    }

    public void onNothingSelected(AdapterView parent) {
    }

    private String[] mStrings = {
            "Push up", "Push left", "Cross fade", "Hyperspace"};

    private ViewFlipper mFlipper;

}

animation_2.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:padding="10dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <ViewFlipper android:id="@+id/flipper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:flipInterval="2000"
                android:layout_marginBottom="20dip" >
                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:textSize="26sp"
                        android:text="@string/animation_2_text_1"/>
                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:textSize="26sp"
                        android:text="@string/animation_2_text_2"/>
                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:textSize="26sp"
                        android:text="@string/animation_2_text_3"/>
                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:textSize="26sp"
                        android:text="@string/animation_2_text_4"/>
    </ViewFlipper>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dip"
        android:text="@string/animation_2_instructions"
    />

    <Spinner android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    />

</LinearLayout>

1.由下到上进入消失

push_up_in.xml

<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

<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" />

2.有右到左进入消失

push_left_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
	<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>

push_left_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300"/>
	<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>

3.渐变进入消失

这是有android自带的

4.在三维上进行动画

hyperspace_in.xml

<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" android:startOffset="1200" />

hyperspace_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">

	<scale
		android:interpolator="@android:anim/accelerate_decelerate_interpolator"
		android:fromXScale="1.0"
		android:toXScale="1.4"
		android:fromYScale="1.0"
		android:toYScale="0.6"
		android:pivotX="50%"
		android:pivotY="50%"
		android:fillAfter="false"
		android:duration="700" />

	<set
		android:interpolator="@android:anim/accelerate_interpolator"
                android:startOffset="700">

		<scale
			android:fromXScale="1.4"
			android:toXScale="0.0"
		        android:fromYScale="0.6"
	 		android:toYScale="0.0"
	 		android:pivotX="50%"
	 		android:pivotY="50%"
	 		android:duration="400" />

		<rotate
			android:fromDegrees="0"
			android:toDegrees="-45"
	 		android:toYScale="0.0"
	 		android:pivotX="50%"
	 		android:pivotY="50%"
	 		android:duration="400" />
	</set>

</set>

2003-view-Animation-push,布布扣,bubuko.com

时间: 2024-10-12 12:50:13

2003-view-Animation-push的相关文章

【Android界面实现】View Animation 使用介绍

转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 我们可以使用view animation 动画系统来给View控件添加tween动画(下称"补间动画"),补间动画通过计算一些动画参数,比如说开始点,结束点,大小,旋转角度和一些其他的动画参数,来实现动画效果. 补间动画可以给View对象添加一系列简单的变换,比如位置,大小,角度或者是透明度.所以,如果你有一个TextView对象,你可以移动,旋转或者是变大.如果它有一个背景图片,背景图片也会随

Android动画三部曲之一 View Animation &amp; LayoutAnimation

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/50612827 本篇文章对android的Tween动画和帧动画以及布局动画进行总结. Tween动画 XML语法介绍 插值器 Interpolator 自定义Interpolator 公共XML属性及对应的方法 ScaleAnimation 缩放动画 xml定义缩放动画 代码定义缩放动画 RotateAnimation 旋转动画 xml中设置旋转动画 代码中设置旋转动画 Transl

【Android 动画】View Animation详解(一)

安卓平台目前提供了两大类动画,在Android 3.0之前,一大类是View Animation,包括Tween animation(补间动画),Frame animation(帧动画),在android3.0中又引入了一个新的动画系统:property animation,即属性动画.本篇文章主要介绍View Animation的基本使用方法与技巧,属性动画将在下一篇博文中介绍. Tween动画可以执行一系列简单变换(位置,大小,旋转,缩放和透明度).所以,如果你有一个TextView对象,您

*Android动画View Animation

Animations 一.Animations介绍 Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转.缩放.淡入淡出等,这些效果可以应用在绝大多数的控件中. 二.Animations的分类 Animations从总体上可以分为两大类: 1.Tweened Animations:该类Animations提供了旋转.移动.伸展和淡出等效果.Alpha——淡入淡出,Scale——缩放效果,Rotate——旋转,Transl

视图动画View Animation入门

View Animation 你可以使用 view animation system 对一个view实现补间动画. A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object.. Theanimation package provides all the classes u

android 动画 ——视图动画(View Animation)

android动画分为视图动画(View Animation).属性动画(Property Animation) 想看属性动画(Property Animation):请移步至http://blog.csdn.net/u013424496/article/details/51700312 这里我们来说下视图动画(View Animation)的纯代码写法,还有一种是xml调用, 对于xml调用可以去看 http://blog.csdn.net/u013424496/article/details

Android动画之二:View Animation

作为一个博客<Android其中的动画:Drawable Animation>.android动画主要分为三大部分.上一篇博客已经解说Drawable Animation的使用方法,即逐帧地显示图片,常常运用于动态显示一个进度动画,这是出现频率最高的应用场景.接下来.我们这篇文章将循序渐进.介绍View Animation. View Animation也是我们平时非常多书籍所说的Tweened Animation(有人翻译为补间动画).View Animation分为4大类:AlphaAni

动画的使用&mdash;View Animation

View Animation定义了下面的四种动画效果: 缩放(scale).位移(translation).旋转(rotation).透明(alpha)   缩放动画: ScaleAnimation(float fromX, float toX, float fromY, float toY, float pivotX, float pivotY) 看ScaleAnimation的构造函数,各个参数的含义都很清楚 fromX: 理解为对象缩放前的宽度 toX:对象x需要缩放到多大 其他的两个带Y

Android Animation学习(六) View Animation介绍

View Animation View animation系统可以用来执行View上的Tween animation和Frame animation. Tween animation可以在View对象上执行一系列的简单变换,比如位置.尺寸.旋转.透明度等. animation package 包中包含了tween animation所有的类. 一系列的动画命令定义了一个完整的tween animation,可以用代码定义也可以用XML资源文件定义. XML资源文件 XML资源文件的使用可以见:A

android.view.animation(2) - 插值器Interpolator

public interface Interpolator implements TimeInterpolator android.view.animation.Interpolator Known Indirect Subclasses AccelerateDecelerateInterpolator, AccelerateInterpolator, AnticipateInterpolator, AnticipateOvershootInterpolator, BounceInterpola