4

我正在使用 Volley 库中的 NetworkImageView 来加载图像。

但是,虽然图像需要时间从 URL 加载,但我想在图像容器中显示旋转/移动加载符号。

我尝试使用 setDefaultImageResId() 函数来设置 loader.gif 图像。但我认为 Android 本身不支持 gif 格式。

请指教。谢谢。

4

3 回答 3

9

你只需要把NetworkImageViewandProgressBar放在 aFrameLayout或 a里面RelativeLayout,像这样

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

     <ProgressBar
            style="?android:attr/progressBarStyle"
            android:layout_width="..."
            android:layout_height="..." />

    <com.android.volley.toolbox.NetworkImageView
        android:layout_width="..."
        android:layout_height="..."
         />

</FrameLayout>

请注意ORDER COUNTS,确保在加载图像后放置在NetworkImageView之后,ProgressBar以便NetworkImageView保持在顶部。ProgressBar

希望能帮助到你!

于 2014-07-17T11:57:02.083 回答
3

你是对的。Android 并不真正支持动画 gif。但好消息是您可以使用内置的进度条/滚轮。在这里阅读。

您必须NetworkImageView使用常规切换您一直在使用ImageView的图像,并使用ImageLoader. 这样你就可以实现一个监听器来切换进度轮。这意味着您需要创建一个RequestQueue和一个ImageLoader. 我建议您创建一个并通过单例类与代码中需要它的任何人共享它们。

图像加载应该类似于以下内容:

// ** code in init the progress wheel **

imageLoader.get(url, new ImageListener() {
    @Override
    public void onResponse(ImageContainer response, boolean isImmediate) {
        if (response != null) {
            Bitmap bitmap = response.getBitmap();
            if (bitmap != null) {
                // ** code to turn off the progress wheel **
                // ** code to use the bitmap in your imageview **
            }

    @Override
    public void onErrorResponse(VolleyError error) {
        // ** code to handle errors **
    }
});
于 2014-04-10T07:35:52.150 回答
1

我已经使用可绘制动画完成了这项工作。以下是步骤:

动画绘制 ic_sync_drawable.xml:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/selected"
    android:oneshot="false">
    <item
        android:drawable="@drawable/ic_popup_sync_1"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_2"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_3"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_4"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_5"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_6"
        android:duration="50" />
</animation-list>

现在在java代码中我使用ImageView:

Drawable drawable = getContext().getResources().getDrawable(R.drawable.ic_sync_drawable);
ImageView imageView = new ImageView(getContext());
imageView.setImageDrawable(drawable);
imageLoader.get(imageurl, ImageLoader.getImageListener(imageView, 0, 0));
ViewFlipper.addView(imageView);
//start animation
 AnimationDrawable frameAnimation = (AnimationDrawable) drawable;
frameAnimation.start();
于 2016-04-15T10:05:54.587 回答