English 中文(简体)
Simple Splash Screen
原标题:

I am trying to follow a simple splash screen example I found. But I cannot get it to even compile.

First this is the source of the example here.

I am trying to put in into a form that would work for my program.

I created a class in Eclipse for this splash screen

com.ePN.ePNMobileAndroid.ePNSplash

Here is my current main.xml file.

<?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> 

And the class itself

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 error:

no resource found that matches the given name (at src with value @drawable/com.ePN.ePNMobileAndroid.splash )

I have tried every way I can think to modify the android:src but it will not work.

The class is in error because it cannot resolve r_id.splashscreen in the find by id line.

This is all greek to me, how should this trivial xml and/or java file be modified to make this work?

问题回答

In android:src="@drawable/com.ePN.ePNMobileAndroid.splash" what are you trying to display in this ImageView? This needs to be a reference to something in your res/drawable directory. So for example if you had a file in res/drawable named my_splash_image.png then the XML attribute would be android:src="@drawable/my_splash_image". Whatever you re trying to do with that package naming inside that attribute isn t going to work.

Looking at the example you are working from, it looks like they had a res/drawable/splash.png file that they were using, that they didn t include in their forum post.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签