您的位置:首页 > 移动开发

仿乐透购彩app(1)

2016-07-23 22:20 399 查看

仿乐透购彩app

通过代码设置无标题,全屏

//设置无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏
getWindow().setFlags(                   WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);


布局:

        


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
android:contentDescription="@null"
android:id="@+id/welcome_img"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/loading" >
</ImageView>

</LinearLayout>


WelcomActivity.java启动界面:是一个图片渐变的过程, 让后跳到主界面:

package com.chb.letou;
import com.chb.letou.util.BitmapUtil;
import com.chb.letou.view.MainView;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
/**
* 启动界面
*/
public class WelcomeActivity extends Activity {
/*
* 屏幕高度
*/
private int screenHeight;
/**
* 屏幕宽度
*/
private int screenWidth;
private boolean flag = true;
private int alpanum=0;
private int count;

Handler hannext = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what==0) {
welcome_imageview.setAlpha(alpanum+=1);
}
if (msg.what==-1) {
welcome_imageview.setAlpha(alpanum-=1);
}
if (msg.what==1) {
nextpage();
}
}
};
private ImageView welcome_imageview;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.welcome);
//获取屏幕的尺寸
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenHeight= dm.heightPixels;
screenWidth =dm.widthPixels;

init();
}

private void init() {
// TODO Auto-generated method stub
welcome_imageview = (ImageView)findViewById(R.id.welcome_img);
Bitmap srcpic = BitmapFactory.decodeResource(getResources(),R.drawable.loading);
Bitmap newpic = BitmapUtil.GetNewBitmap(srcpic, screenWidth, screenHeight,screenWidth, screenHeight);
welcome_imageview.setImageBitmap(newpic);
new Thread(new Runnable() {

public void run() {
while (flag) {
try {
Thread.sleep(10);
count++;
hannext.sendEmptyMessage(0);
if (count>255) {
hannext.sendEmptyMessage(-1);
}
if (count>500) {
hannext.sendEmptyMessage(1);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
private void nextpage(){
flag=false;
finish();
Intent intent = new Intent(WelcomeActivity.this,MainView.class);
startActivity(intent);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}


改进:使用补间动画(Tween Animation)

第一步: 在res/anim文件夹下创建一个动画的设置文件

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true" >

<!-- fromAlpha和toAlpha是起始透明度和结束时透明度 -->
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:startOffset="500"
android:toAlpha="1.0" />

<!--
起始x轴坐标
止x轴坐标
始y轴坐标
止y轴坐标
轴的坐标
轴的坐标

-->
<scale
android:duration="2000"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />

</set>


第二步:

   设置动画, 启动动画

//使用AnimationUtils加载动画配置文件
Animation animation =
AnimationUtils.loadAnimation(WelcomeActivity.this, R.anim.loading);
//启动动画
welcome_imageview.setAnimation(animation);


package com.chb.letou;

import com.chb.letou.view.MainView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
/**
* 启动界面
*/
public class WelcomeActivity extends Activity {

private ImageView welcome_imageview;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.welcome);
init();
}

private void init() {
welcome_imageview = (ImageView)findViewById(R.id.welcome_img);

//使用AnimationUtils加载动画配置文件 Animation animation = AnimationUtils.loadAnimation(WelcomeActivity.this, R.anim.loading); //启动动画 welcome_imageview.setAnimation(animation);
//跳到主界面
nextpage();

}
private void nextpage(){

Intent intent = new Intent(WelcomeActivity.this,MainView.class);
startActivity(intent);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}


发现问题: 启动界面的动画还没有结束,就跳到了新的界面, 并不是在动画执行完成,而进行finish() ,跳到新的界面。

进一步的改进: 设置动画执行的监听,setAnimationListener()

welcome_imageview = (ImageView)findViewById(R.id.welcome_img);

//使用AnimationUtils加载动画配置文件
Animation animation =
AnimationUtils.loadAnimation(WelcomeActivity.this, R.anim.loading);
//启动动画
welcome_imageview.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
//动画执行结束

//跳到主界面
nextpage();
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  仿乐透购彩app