首页 > 代码库 > xml动画
xml动画
anim中的四个xml文件:
1.alpha.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="3000" android:fromAlpha="0.1" android:toAlpha="1.0" /></set>
2.scale.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="2000"/></set>
3.translate.xml:
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="30" android:toXDelta="100" android:fromYDelta="30" android:toYDelta="100" android:duration="2000"/></translate>
4.rotate.xml:
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="+720" android:pivotX="50%" android:pivotY="50%" android:duration="2000"/></rotate>
layout中的xml文件activity_main.xml:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="你是一坨屎!!" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/textView1" android:layout_centerHorizontal="true" android:src="@drawable/aa20140903173350" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="131dp" android:text="渐变" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/button1" android:text="收缩" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_toRightOf="@+id/button2" android:text="移动" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button3" android:layout_alignBottom="@+id/button3" android:layout_toRightOf="@+id/button3" android:text="旋转" /></RelativeLayout>
src中的.java文件MainActivity.java:
package com.anim.anim;import android.os.Bundle;import android.app.Activity;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.ImageView;import android.widget.TextView;public class MainActivity extends Activity { private TextView txt; private ImageView img; Animation animation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img=(ImageView) findViewById(R.id.img); txt=(TextView) findViewById(R.id.textView1); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.alpha); img.startAnimation(animation); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale); img.startAnimation(animation); } }); findViewById(R.id.button3).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.translate); img.startAnimation(animation); } }); findViewById(R.id.button4).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate); img.startAnimation(animation); } }); }}
xml动画
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。