问题描述
在我上一个Android的PhoneGap项目工作的时刻。
At the moment I work on an android-phonegap project.
在应用程序加载的index.html有一些本土code做的工作。在细节它在AsyncTask的是寻花问柳SD卡(如果可用)。
Before the app loads the index.html there is some native code doing work. In detail it's in AsyncTask which is knocking around on the SD card (if available).
我设法证明,而A.Task工作进度栏,但另外我想在后台添加一个启动画面。我大多与PhoneGap的工作,只是与本地code开始。所以我还挺所有这些布局,主题还有什么你可能在.xml文件中定义混淆。我是pretty相信这也是更大的UI设计,但对于简单的启动画面我现在感觉就像一个总矫枉过正想个好主意。
I managed to show a progress bar while the A.Task is working but furthermore I'd like to add a Splash screen in the background. I mostly worked with Phonegap and just start with native code. So I'm kinda confused by all these layouts, themes and what else you may define in the .xml files. I'm pretty sure it's also a good idea for bigger UI designs but for the simple Splash screen I want right now it feels like a total overkill.
这是从源代码片段。只是直线前进。的onCreate()调用的AsyncTask至极做了一些工作,并在它的PostExecute方法开始的PhoneGap。我想在屏幕上出现无论是在onCreate方法或preExecute。任务完成的画面后我会驳回onPostExecute屏幕()。我还添加注释来说明我的想法。
This is a snippet from the source. Just straight forward. onCreate() calls the AsyncTask wich does some work and starts PhoneGap in it's PostExecute method. I'd like the screen to appear either in the onCreate method or onPreExecute. After the job is done the screen I'd dismiss the screen in onPostExecute(). I also added comments to illustrate my idea.
public class myAct extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Show Splash here or in onPreExecute()!
new myAsTa().execute();
}
}
class myAsTa extends AsyncTask<Void, Integer, Boolean> {
ProgressDialog dialog = new ProgressDialog(myAct.this);
@Override
protected void onPreExecute() {
//or show splash here!
dialog.setMessage("Cool Progressbar!");
dialog.show();
super.onPreExecute();
}
protected Boolean doInBackground(Void... values) {
//magician at work!
return true;
}
@Override
protected void onProgressUpdate(Integer... values) {
//insult user here
}
protected void onPostExecute(Boolean result) {
dialog.dismiss();
//dismiss splashscreen
//start Phonegap
}
}
感谢您的阅读与你的帮助:)
Thanks for reading and your help :)
推荐答案
我曾经做过这样一个闪屏here.这将加载飞溅布局和本身当应用程序被加载直接从系统触发(的AndroidManifest.xml 一>)
I have done such a splash screen here. This loads the splash layout and is itself triggered directly from the system when the app is loaded (AndroidManifest.xml)
<activity android:name=".SplashActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
什么是屏幕上显示在的setContentView(R.layout.splash)定义;
- 这个布局基本
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/desktop_rhq"
>
<TextView android:layout_gravity="bottom"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/loading"
/>
</LinearLayout>
其中定义一个背景图像和一些文本被显示。说实话,我没有想过太多关于方向的变化飞溅运行时 - 我想这将重新启动后台任务
Which defines a background image and some text to be shown. To be honest, I haven't thought much about orientation change while the splash is running - I guess this will restart the background task.
这篇关于而AsyncTask的运行的是Android闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!