且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在结果显示之前添加加载,我将滑行用于图像显示

更新时间:2023-12-05 17:23:52

我遇到了同样的问题.我通过使用picasso库解决了它.在此处

I had same problem. I solved it by using picasso library. find the download link here

然后尝试这个.

ProgressBar spinner = (ProgressBar) findViewById(R.id.loading);
spinner.setVisibility(View.VISIBLE);

Picasso.with(getApplicationContext())
       .load((your URL)
            .into(imageView, new Callback() {
                    @Override
                    public void onSuccess() {
                        spinner.setVisibility(View.GONE);
                    }

                    @Override
                    public void onError() {
                        spinner.setVisibility(View.GONE);
                        imageView
                                .setBackgroundResource(R.drawable.small_logo);
                    }
                });

在这里,我将ImageViewProgressBar(上面代码中的旋转器)包装在RelativeLayout中.

Here I have wrap ImageView and ProgressBar(spinner in above code) in RelativeLayout.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip" >

<ImageView
    android:id="@+id/imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:scaleType="fitXY" />

<ProgressBar
    android:id="@+id/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone" /></FrameLayout>

希望这对您有所帮助.