HappyIdiom之一闪屏实现

本文详细介绍了闪屏界面的设计与实现过程,包括不同分辨率图片的存放位置、布局设计、文字换行、无标题栏实现、闪屏显示时长设置及动画效果应用。通过实例展示了如何利用AlphaAnimation和Handler实现2秒跳转至主界面的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目标:实现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又是什么东东呢?

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值