码迷,mamicode.com
首页 > 其他好文 > 详细

动画综合练习(延迟进入+页面向导+文本框抖动)

时间:2015-03-12 22:38:00      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

1、activity_welcome.xml(界面刚加载进入欢迎界面的布局)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_welcome_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/welcome_back"
    android:gravity="center_horizontal|bottom">
    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:indeterminateDrawable="@anim/image_progress"
        android:indeterminateDuration="500"/>
</LinearLayout>
2、image_progress.xml(欢迎界面启动后,屏幕底部会有一个旋转的加载进度条)

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
   	 android:drawable="@drawable/progess2"/>

3、WelcomeActivity.java

package com.atguigu.l10_app2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.LinearLayout;
/**
 * 欢迎界面
 *
 */
public class WelcomeActivity extends Activity {
	private LinearLayout ll_welcome_root;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		
		ll_welcome_root = (LinearLayout) findViewById(R.id.ll_welcome_root);
		//调用启动动画效果
		showAnimation();
	}
	
	//接受消息、处理消息
	private Handler handler = new Handler(new Handler.Callback() {
		@Override
		public boolean handleMessage(Message msg) {
			if(msg.what==1) {
				//接受到消息后,启动另一个界面
				startActivity(new Intent(WelcomeActivity.this, Guide1Activity.class));
			}
			return true;
		}
	});
	/**
	 * 显示动画
	 */
	private void showAnimation() {
		//设置图片背景透明度
		AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
		animation.setDuration(2000);
		//设置动画监听
		animation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				//发送延迟的空消息
				handler.sendEmptyMessageDelayed(1, 1000);
			}
		});
		//欢迎界面的启动动画效果界面
		ll_welcome_root.startAnimation(animation);
	}
}
4、然后进入第一个向导界面如图

技术分享

先看向导界面1的布局文件

activity_guide1.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"
    tools:context="com.atguigu.l10_app2.Guide1Activity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第一个设置" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="下一步" 
        android:onClick="next"/>
</RelativeLayout>
Guide1Activity.java(代码作用是启动界面向导二,以及显示向导界面1和2的切换效果)

package com.atguigu.l10_app2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class Guide1Activity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide1);
	}

	public void next(View v) {
		startActivity(new Intent(this, Guide2Activity.class));
		//显示一个界面切换的动画
		overridePendingTransition(R.anim.anim_right_in, R.anim.anim_left_out);
	}
}
anim_left_out.xml(当前页面向左滑动)

<?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%"
    android:toXDelta="-100%" 
    android:duration="1000">
</translate>
anim_right_in.xml(下一张页面向左滑动进入到当前页面)

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="100%" 
    android:toXDelta="0%"
    android:duration="1000">
</translate>

5、接下来看向导页面2的布局


技术分享


activity_guide2.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"
    tools:context="com.atguigu.l10_app2.Guide1Activity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第二个设置" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:onClick="next"
        android:text="下一步" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button2"
        android:layout_alignBottom="@+id/button2"
        android:layout_alignParentLeft="true"
        android:text="上一步" 
        android:onClick="pre"/>

</RelativeLayout>
Guide2Activity.java(向导二的java代码,作用是点击下一张,和点击上一张,显示页面切换的滑动效果)

package com.atguigu.l10_app2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class Guide2Activity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide2);
	}
	
	public void next(View v) {
		startActivity(new Intent(this, MainActivity.class));
	}
	
	public void pre(View v) {
		finish();
		
		//显示一个界面切换的动画
		overridePendingTransition(R.anim.anim_left_in, R.anim.anim_right_out);
	}
}

另外附上点击返回上一张界面的xml文件

anim_left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="-100%" 
    android:toXDelta="0%"
    android:duration="500">
</translate>
anim_right_out.xml

<?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%"
    android:toXDelta="100%" 
    android:duration="500">
</translate>


6、接下来进入主界面了(这个效果是文本框抖动效果)

技术分享

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"
    tools:context="com.atguigu.l10_app2.MainActivity" >

    <EditText
        android:id="@+id/et_main_number"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/et_main_number"
        android:text="提交" 
        android:onClick="submit"/>

</RelativeLayout>
MainActivity.java

package com.atguigu.l10_app2;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;

public class MainActivity extends Activity {

	private EditText et_main_number;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		et_main_number = (EditText) findViewById(R.id.et_main_number);
	}
	
	public void submit(View v) {
		//水平振动
		Animation animation = AnimationUtils.loadAnimation(this, R.anim.shake);
		et_main_number.startAnimation(animation);
	}
}

实现水平震动的需要下面xml文件支持

cycle_6.xml

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="6"/>

shake.xml

<?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0.1"
    android:toXDelta="1.0"
    android:duration="500"
    android:interpolator="@anim/cycle_6">
    <!-- 配置文件里不能有f出现 -->
</translate>





动画综合练习(延迟进入+页面向导+文本框抖动)

标签:

原文地址:http://blog.csdn.net/u013210620/article/details/44227209

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!