HappyIdiom之一閃屏實現

目標:實現HappyIdiom閃屏

問題1:那麼多drawble文件夾,究竟該將圖片放在哪裏呢?

1.drawable-(hdpi,mdpi,ldpi)的區別
dpi是“dot per inch”的縮寫,每英寸像素數。
四種密度分類: ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high)
一般情況下的普通屏幕:ldpi是120,mdpi是160,hdpi是240,xhdpi是320。

2.WVGA,HVGA,QVGA的區別
VGA是”Video Graphics Array”,顯示標準爲640*480。
WVGA(Wide VGA)分辨率爲480*800
HVGA(Half VGA)即VGA的一半分辨率爲320*480
QVGA(Quarter VGA)即VGA非四分之一分辨率爲240*320

3.drawable-(hdpi,mdpi,ldpi)和WVGA,HVGA,QVGA的聯繫
hdpi裏面主要放高分辨率的圖片,如WVGA (480×800),FWVGA (480×854)
mdpi裏面主要放中等分辨率的圖片,如HVGA (320×480)
ldpi裏面主要放低分辨率的圖片,如QVGA (240×320)
系統會根據機器的分辨率來分別到這幾個文件夾裏面去找對應的圖片

問題2:如何進行閃屏界面的佈局呢?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/bg_ling" >

    <ImageView
        android:id="@+id/welcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="45dp"
        android:src="@drawable/welcome" />

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/welcome"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="66dp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/welcome"
        android:layout_centerHorizontal="true"
        android:text="@string/welcome"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="30sp" />

</RelativeLayout>

技巧:如何實現文字換行呢?

 <string name="welcome">跟我一起學成語吧\n中國成語真奇妙</string>

如何實現無標題欄呢?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bzu.happyidiom.controller"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:theme="@android:style/Theme.NoTitleBar"
            android:name=".WelcomeActivity"
            android:label="@string/title_activity_welcome" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

問題3:如何實現閃屏顯示2秒鐘跳到主界面呢?

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
/**
 * 閃屏界面
 */
public class WelcomeActivity extends Activity {

	private ImageView welcomeImage;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        welcomeImage=(ImageView) this.findViewById(R.id.welcome);
        //定義1個具有淡入效果的對象
        AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);
        alphaAnimation.setDuration(3000);
        welcomeImage.startAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				Intent intent=new Intent();
				intent.setClass(WelcomeActivity.this, MainActivity.class);
				startActivity(intent);
				finish();
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_welcome, menu);
        return true;
    }

    
}

 

實現閃屏的另外一種方式:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        welcomeImage=(ImageView) this.findViewById(R.id.welcome);
        //定義1個具有淡入效果的對象
        AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);
        welcomeImage.startAnimation(alphaAnimation);
        new Handler().postDelayed(new Runnable() {		
			@Override
			public void run() {
				Intent intent=new Intent();
				intent.setClass(WelcomeActivity.this, MainActivity.class);
				startActivity(intent);
				finish();
			}
		},3000);
    }


微笑閃屏的設計就說到這裏了,當然這裏面還有一些沒有展開的話題,大家可以深入學習

  • AlphaAnimation類的使用是不是可以實現更炫的動畫效果呢?
  • Handler又是什麼東東呢?

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章