如何将应用程序预加载器/启动屏幕/启动画面添加到我的PhoneGap Android应用程序
问题描述:
我已经使用手机差距创建了一个Android应用程序。它工作正常。如何向我的应用程序添加预加载器图像。现在它显示加载应用程序时显示一个白页。如何将应用程序预加载器/启动屏幕/启动画面添加到我的PhoneGap Android应用程序
非常感谢帮助, 谢谢, VKS。
答
如果您的意思是预加载器映像有闪屏,请参考以下代码;
为PhoneGap的:
public class MyDefaultActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash); // Displays the splash screen for android
super.loadUrl("file:///android_asset/www/index.html",3000); // Second parameter is duration for delay of splash screen
}
}
对于Android原生应用:
public class MySplashScreen extends Activity {
private CountDownTimer lTimer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splashscreen); // Contains only an LinearLayout with backround as image drawable
lTimer = new CountDownTimer(5000, 1000) {
public void onFinish() {
closeScreen();
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
}.start();
}
private void closeScreen() {
Intent lIntent = new Intent();
lIntent.setClass(this, MyLauncherActivity.class);
startActivity(lIntent);
finish();
}
}
确保一个名为splash.png
文件存在为res/drawable-hdpi/splash.png
(RGBA)。
答
您可以创建AsyncTask
实现来显示图像/进度指示器,同时在后台线程中加载应用程序的数据。
- 在异步任务的
onPreExecute
方法告诉你所选择的预加载 (图像/ ProgressDialog /等)在doInBackground
方法,你 开始在onPostExecute
方法加载必要的数据, 和 - 你 删除/隐藏你的preloader,所以 活动的预期布局将显示 显示。
答
如果通过预加载图像您指的是大图像的低分辨率版本,您可以使用VewSwitcher带有两个ImageViews:一个图像视图包含预加载图像,而其他包含完整的图像(而它被加载)。最初,您可以使预加载的图像可见,但是当大Bitmap完成加载时,只需使用switcher.showNext()
即可显示完整图像。
有关ViewSwitcher(例子中做类似的东西)的一些进一步阅读:我想问一下,如果我有针对Android的WebView应用程序代码here
喜@ Vinayak.B,但之前的WebView完全加载我想说明我的公司徽标图像第一..我在这里写了一个问题:http://stackoverflow.com/questions/16701179/how-to-change-background-image-on-android-progress-dialog我真的需要你的建议,谢谢 :) – bungdito 2013-05-22 20:50:15