前几天我发现了非常棒的教程:进阶动画闪屏,我是android开发的新手,这个教程对制作令人敬畏的闪屏非常有帮助。
但是我需要更多的帮助来修改代码,我需要在闪屏后加载我的webview活动,如果可能的话,我想使闪屏作为我的webview预加载器或至少使webview活动作为背景活动,所以当闪屏出现时,我的webview不需要太多的时间来加载了。
序列1. 用户点击应用程序图标
2. animation_splashscreen出现(但不仅等待5000,而且加载我的webview)
3.(不再加载…然后…)我的webview出现
我已经尝试了它的工作很好,但是有像我加载两次,,在闪屏消失后,我的网页视图出现加载/进度条。
我的问题是,我可以应用启动屏幕作为我的webview预加载器吗?所以开机画面将在webview完全加载到设备上后消失,然后直接打开webview(在我的webview上不再加载)
可能有人告诉我一步一步请,因为我是非常非常新手在android开发..我试着学习启动屏幕,而在android应用程序的webview加载一个url,但我不能理解当我想使动画溅屏:(
下面是我的代码:在SplashScreen.java
package com.yourname.main;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.ImageView;
public class SplashScreen extends Activity {
/**
* The thread to process splash screen events
*/
private Thread mSplashThread;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Splash screen view
setContentView(R.layout.splash);
// Start animating the image
final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
splashImageView.setBackgroundResource(R.drawable.flag);
final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
splashImageView.post(new Runnable(){
@Override
public void run() {
frameAnimation.start();
}
});
final SplashScreen sPlashScreen = this;
// The thread to wait for splash screen events
mSplashThread = new Thread(){
@Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
wait(5000);
}
}
catch(InterruptedException ex){
}
finish();
// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen, WebViewActivity.class);
startActivity(intent);
//stop();
}
};
mSplashThread.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
return false;
}
/**
* Processes splash screen touch events
*/
@Override
public boolean onTouchEvent(MotionEvent evt)
{
if(evt.getAction() == MotionEvent.ACTION_DOWN)
{
synchronized(mSplashThread){
mSplashThread.notifyAll();
}
}
return true;
}
}
和WebViewActivity.java
package com.yourname.main;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...",true);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if(pd.isShowing()&&pd!=null)
{
pd.dismiss();
}
}
});
webView.loadUrl("http://google.com");
setTitle("Google Search");
}
}
从你的问题来看,你不需要启动屏。
你可以这样做:
- 忘记SplashScreen活动 直接打开WebViewActivity
- 添加splash ImageView到你的webview.xml
- 设置启动图像
- 设置webView可见性为INVISIBLE
- 在onPageFinished期间设置webView可见性为VISIBLE, splash ImageView为GONE
基本上你将在webview的顶部显示一个图像,一旦页面加载,你将删除该图像并显示webview