Android:加载时显示屏幕

发布于 2025-01-07 08:19:19 字数 1065 浏览 3 评论 0原文

我正在使用 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) {

//here i get the data from the server

        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() 中,我需要再次隐藏此“等待”屏幕,但我该怎么做呢? 感谢您的帮助!

I am using AsyncTask to get data from a server and want to show a Screen while it is loading like this:

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) {

//here i get the data from the server

        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);
        }
    }
}

Now, in onPostExecute() I need to hide this "Wait" Screen again, but how do I do that?
Thanks for helping!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

穿越时光隧道 2025-01-14 08:19:19

您可以在 PopupDialog 中显示图像并在 onPostExecute 中关闭它,而不是启动不同的活动

instead of starting a different activity you can show your image in a PopupDialog and close it in onPostExecute

明天过后 2025-01-14 08:19:19

使用此布局代替...

<?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() 上隐藏 imageView 和显示实际布局。

Use This Layout instead ...

<?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>

Now on preExecute() show the waiting imageview and hide the actual layout.

And on postExecute() hide the imageView & show the actual layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文