标签:anim
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1000" android:fromXDelta="0" android:toXDelta="100%p" /> <alpha android:duration="1000" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
各属性的意思:
fromXDelta:该控件的X轴作为起点
toXDelta:以该控件的Y轴作为重点
fromAlpha:动画起始的透明度
toAlpha:动画结束的透明度
duration:整个动画的时间,单位毫秒
直接上代码
package com.example.testanim; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.Button; public class AnimActivity extends Activity { private Animation anim; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_anim); anim = AnimationUtils.loadAnimation(this, R.anim.slide); } public void start(View v){ btn = (Button) findViewById(R.id.button1); View v2 = btn; v2.startAnimation(anim); anim.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub btn.setVisibility(View.GONE); } }); } }
//layout布局,很简单只有两个按钮
//点击下面的按钮,控制上面的按钮,开始动画
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="我是动画" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="start" android:text="点击" /> </LinearLayout> </LinearLayout>
整个动画讲解
点击小按钮,上面的长按钮开始动画
从左向右运动,颜色慢慢变淡,当按钮滑到最后边时,颜色刚好为透明。
http://670176656.blog.51cto.com/addblog.php
本文出自 “爬过山见过海” 博客,请务必保留此出处http://670176656.blog.51cto.com/4500575/1681397
标签:anim
原文地址:http://670176656.blog.51cto.com/4500575/1681397