我正在制作一个带有webview的应用程序。这个webview通过加载url使用了一些时间,所以我希望Imageview在它消失之前显示约3秒。这是我的布局文件。在应用程序启动3秒后,如何在这两个视图上交换可见性?
<ImageView android:id="@+id/imageLoading1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="visible"
android:src="@drawable/logo"
/>
<android.webkit.WebView
android:id="@+id/wvwMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
>
答案 0 :(得分:4)
new Handler().postDelayed(new Runnable() {
public void run() {
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
findViewById(R.id.wvwMain).setVisibility(View.VISIBLE);
}
}, 3000);
这将在后台等待3秒,之后它会更改回UI线程并设置可见性。
答案 1 :(得分:1)
imageView.postDelayed(new Runnable(){
public void run(){ imageView.setVisibility(View.GONE);}
},3000);
答案 2 :(得分:0)
此代码是一个示例,说明如何使用CountDown。
import android.os.CountDownTimer;
public class Sample extends Activity {
MyCustomCountDown timer;
ImageView imageview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageview = (ImageView) findViewById(R.id.imageLoading1);
timer = new MyCustomCountDown(3 * 1000, 1000);
timer.start();
}
public class MyCustomCountDown extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
//some script here
imageview.setVisible(View.GONE); ////HERE HIDE YOUR IMAGE.
}
@Override
public void onTick(long millisUntilFinished) {
//some script here
}
}
}
答案 3 :(得分:0)
试试这个JavaScript:
myImageView.postDelayed(
new Runnable(){
public void run(){
myImageView.setVisibility(View.GONE);
}
},3000);