MainActivity.java

package com.example.crystalball;

import android.support.v4.app.Fragment;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends Activity { private static final String Tag = "MainActivity"; Button mButton;
TextView mTextView;
ImageView mImageView;
Animation mAnimation;
Animation mFadein;
SoundPool mSoundPool;
int click; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main); Log.v(Tag, "onCreate()"); mButton = (Button) findViewById(R.id.button1);
mTextView = (TextView) findViewById(R.id.textView1);
mImageView = (ImageView) findViewById(R.id.imageView1);
mAnimation = AnimationUtils.loadAnimation(this, R.anim.zoomin);
mFadein = AnimationUtils.loadAnimation(this, R.anim.fadein);
mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
click = mSoundPool.load(this, R.raw.click, 1); mButton.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String answer = "Hello World";
mTextView.setText(answer);
mTextView.startAnimation(mFadein);
mImageView.startAnimation(mAnimation); playSound();
toast("跳转成功");
startAnotherActivity();
}
}); } //通过intent跳转到另一个activity
private void startAnotherActivity() {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
} private void showDialog() {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(this);
mBuilder.setTitle("提示");
mBuilder.setMessage("确认关闭?");
mBuilder.setPositiveButton("确认", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
MainActivity.this.finish();
}
}); mBuilder.setNegativeButton("取消", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
}); mBuilder.create().show();
} @Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.v(Tag, "onStart()");
} @Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.v(Tag, "onRestart()");
} @Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.v(Tag, "onResume()");
} @Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.v(Tag, "onPause()");
} @Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.v(Tag, "onStop()");
} @Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.v(Tag, "onDestroy()");
} //按下退出键时
@Override
public void onBackPressed() {
showDialog();
} //播放声音
private void playSound() { mSoundPool.play(click, 1, 1, 0, 0, 1);
} //toast提示
private void toast(String content) {
Toast mToast = Toast.makeText(this, content, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.show(); }
@Override
public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} /**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() {
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
} }

fadein.xml

 <?xml version="1.0" encoding="utf-8"?>
<!-- alpha: 渐变透明度动画效果 -->
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="2000"
xmlns:android="http://schemas.android.com/apk/res/android"> </alpha>

zoomin.xml

 <?xml version="1.0" encoding="utf-8"?>
<!-- scale: 渐变尺寸伸缩动画效果 -->
<scale
android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
xmlns:android="http://schemas.android.com/apk/res/android"> </scale>

最新文章

  1. 在开启DRS的集群中修复VMware虚拟主机启动问题
  2. python_接口开发
  3. Jquery.load() 使用
  4. mysql 连接空闲超8小时自动断开连接问题(linux)
  5. VB鼠标指针
  6. FreeBSD 10 发布
  7. Oracle —— 表结构相关的SQL
  8. AC题目简解-线段树
  9. python学习day4--python基础--字典
  10. ContentProvider初阶Cookbook
  11. java 短信发送例子 2
  12. hdu 5510 Bazinga(暴力)
  13. mysql提示Column count doesn&#39;t match value count at row 1错误
  14. .net dynamic动态加属性
  15. Andorid开发中如何去除标题栏title
  16. 自学Zabbix3.5.3-监控项item-key
  17. Nginx配置http跳转https访问
  18. vue中Axios的封装和API接口的管理
  19. 纯CSS绘制的三角形箭头图案【原创】
  20. js ParseUrl

热门文章

  1. 并发案例--ScheduledExecutorService用法
  2. Oracle常用操作-----(二)
  3. JQ 全选、全不选
  4. Timing path
  5. html5,新增的元素,fieldset legend
  6. Elementory os install .net core
  7. animation 的属性一共有 6 个值,详细介绍在此
  8. Wamp 设置 www 目录
  9. How to use usercontrol - pass paramters
  10. shiro 从入门到放弃