Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:加载时显示屏幕_Android_User Interface_Screen - Fatal编程技术网

Android:加载时显示屏幕

Android:加载时显示屏幕,android,user-interface,screen,Android,User Interface,Screen,我使用AsyncTask从服务器获取数据,并希望在加载时显示屏幕,如下所示: private class GetListTask extends AsyncTask { protected void onPreExecute() { Intent intent = new Intent(); intent.setClass(Start.this, Wait.class); startActivity(

我使用AsyncTask从服务器获取数据,并希望在加载时显示屏幕,如下所示:

private class GetListTask extends AsyncTask {
    protected void onPreExecute() {
            Intent intent = new Intent();
                intent.setClass(Start.this, Wait.class);
                startActivity(intent);
    }

    protected Bitmap doInBackground(Object... args) {
//这里我从服务器获取数据

        d = getImageFromURL(Start.valuesArray[Integer.parseInt(Value)][7]);
        Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
        double ratio = (double) bitmap.getWidth() / (double) bitmap.getHeight();
        Bitmap scaled = Bitmap.createScaledBitmap(bitmap, width, (int) (width / ratio), true);
        return scaled;
    }

    protected void onPostExecute(Object objResult) {
        if (objResult != null && objResult instanceof Bitmap) {
            Bitmap result = (Bitmap) objResult;

            im.setImageBitmap(result);
        }
    }
}
现在,在onPostExecute()中,我需要再次隐藏这个“等待”屏幕,但我该如何做呢?
谢谢你的帮助

您可以在弹出对话框中显示图像,并在onPostExecute中关闭图像,而不是启动其他活动。使用此布局代替

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!--  Your actual layout. width & height fill_parent -->

    <ImageView 
        android:id="@+id/wait_image"
        android:layout_width="fill_parent"
        android:visibility="gone"
        android:layout_height="fill_parent"
        android:src="@drawable/wait_screen"
    />
</FrameLayout>

现在打开
preExecute()
显示等待的图像视图并隐藏实际布局


然后在
postExecute()
上隐藏图像视图并显示实际布局。

您是否正在从
onPreExcute()
开始的
活动中进行一些工作?或者它只是一个图像?如何隐藏当前布局?如何正确显示等待的图像视图?请使用
serviability()
方法。例如-
findViewById(R.id.wait\u image)。setVisibility(View.VISIBLE)
将显示imageView和
findViewById(R.id.your\u layout\u id)。setVisibility(View.GONE)
将隐藏布局。