2010-01-13 126 views
2

我想跟着我找到的一個簡單的初始屏幕示例。但我無法得到它甚至編譯。簡單的初始屏幕

首先,這是該示例的源:

http://www.anddev.org/simple_splash_screen-t811.html

我試圖把在成會爲我的程序工作的形式。

我創建Eclipse的一個類這個閃屏

com.ePN.ePNMobileAndroid.ePNSplash

這裏是我當前的main.xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content" 
      android:layout_height="fill_parent" android:src="@drawable/com.ePN.ePNMobileAndroid.splash" 
      android:layout_gravity="center"/> 
    <TextView android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:text="Hello World, splash"/> 
</LinearLayout> 

和階級本身

package com.ePN.ePNMobileAndroid; 

import android.app.Activity; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.view.View; 
import android.widget.ImageView; 

public class ePNSplash extends Activity { 
    private static final int STOPSPLASH = 0; 
    //time in milliseconds 
    private static final long SPLASHTIME = 3000; 

    private ImageView splash; 

    //handler for splash screen 
    private Handler splashHandler = new Handler() { 
     /* (non-Javadoc) 
      * @see android.os.Handler#handleMessage(android.os.Message) 
      */ 
     @Override 
     public void handleMessage(Message msg) { 
       switch (msg.what) { 
       case STOPSPLASH: 
        //remove SplashScreen from view 
        splash.setVisibility(View.GONE); 
        break; 
       } 
       super.handleMessage(msg); 
     } 
    }; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main); 
       splash = (ImageView) findViewById(R.id.splashscreen); 
       Message msg = new Message(); 
       msg.what = STOPSPLASH; 
       splashHandler.sendMessageDelayed(msg, SPLASHTIME); 
    } 
} 

的XML有一個錯誤說:

「無資源發現在給定的名稱與值匹配(在SRC'@drawable/com.ePN .ePNMobileAndroid.splash')「

我已經試過了我能想到的所有修改android:src的方法,但它不起作用。

該類存在錯誤,因爲它無法解析id by find行中的r_id.splashscreen。

這對我來說都是希臘語,應該如何修改這個微不足道的xml和/或java文件來實現這個功能?

感謝名單

朱利安

+0

你試過'@ drawable/com.ePN.ePNMobileAndroid.ePNSplash'嗎? – 2010-01-13 20:40:35

+0

相同的結果,除了它列出「@ drawable/com.ePN.ePNMobileAndroid.ePNSplash」 – Bodger 2010-01-13 20:43:34

回答

8

android:src="@drawable/com.ePN.ePNMobileAndroid.splash"什麼是你想在這個ImageView的顯示?這需要參考res/drawable目錄中的內容。例如,如果您的文件名爲my_splash_image.png,那麼XML屬性將爲android:src="@drawable/my_splash_image"。無論你想用該屬性中的包命名做什麼都行不通。

看着你正在使用的例子,它看起來像他們有一個res/drawable/splash.png文件,他們正在使用,他們沒有包括在他們的論壇帖子。

+0

是的,事實證明我沒有你指出的圖像。 TY – Bodger 2010-01-25 21:23:58

+6

如果解決了您的問題,請將答案標記爲已接受。謝謝。 – 2010-01-25 21:39:55