編輯:Android開發實例
welcome_glide.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewFlipper android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Java代碼
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.GestureDetector.OnGestureListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ViewFlipper;
import static android.view.KeyEvent.KEYCODE_BACK;
public class WelcomeGlide extends Activity implements OnGestureListener{
private static final String TAG = "Fuchangle.AggHelp";
private int mScreenWidth ;
private int mScreenHeight ;
private GestureDetector detector;
private ViewFlipper flipper;
private int mIndexHelpPic = 0;
private int[] mBgList = {
R.drawable.guide01,
R.drawable.guide02,
R.drawable.guide03,
R.drawable.guide04,
R.drawable.guide05
};
@Override
protected 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_glide);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
mScreenWidth = dm.widthPixels;
mScreenHeight = dm.heightPixels;
if(mScreenWidth <240){
mScreenWidth = 240;
}
if(mScreenHeight < 320){
mScreenHeight = 320;
}
flipper = (ViewFlipper)this.findViewById(R.id.viewflipper);
flipper.addView(addImageByID(mBgList[mIndexHelpPic]), new ViewGroup.LayoutParams
(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT));
detector = new GestureDetector(this);
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if(e1.getX()-e2.getX() > 120){
if(++mIndexHelpPic >= mBgList.length){
mIndexHelpPic = mBgList.length - 1;
backToMainDesk();
return true;
}
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
flipper.addView(addImageByID(mBgList[mIndexHelpPic]),new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
this.flipper.showNext();
}else if(e1.getX() - e2.getX()< -120){
if(--mIndexHelpPic < 0){
mIndexHelpPic = 0;
return true;
}
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
this.flipper.showPrevious();
return true;
}
return true;
}
private void backToMainDesk(){
startActivity(new Intent(this,QQActivity.class));
finish();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KEYCODE_BACK:
backToMainDesk();
return true;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
private View addImageByID(int id){
ImageView img = new ImageView(this);
img.setImageResource(id);
img.setAdjustViewBounds(true);
img.setMaxWidth(mScreenWidth);
img.setMaxHeight(mScreenHeight);
img.setScaleType(ImageView.ScaleType.FIT_XY);
return img;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.i("Fling", "Activity onTouchEvent!");
return this.detector.onTouchEvent(event);
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}
下面的文件放在res/anim裡面
push_left_in.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">>
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="500"/>
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
android:duration="500"/>
</set>
push_left_out.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="500" />
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
android:duration="500" />
</set>
push_right_in.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:duration="500" />
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
android:duration="500" />
</set>
push_right_out.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="500" />
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
android:duration="500" />
</set>
Android應用程序可以在許多不同地區的許多設備上運行。為了使應用程序更具交互性,應用程序應該處理以適合應用程序將要使用的語言環境方面的文字,數字,文件等。在本章中,我
本文實例講述了Android使用WebView播放flash及判斷是否安裝flash插件的方法。分享給大家供大家參考。具體實現方法如下: 一、問題: 最近幫一個同
對於很多初學者或者剛工作的Android新手來說,我們的項目經驗還停留在做demo的階段,有沒有一種很low的感覺,並且當你真正上手做大項目的時候又
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個