问题描述
我如何在Android中增加一个进度条到 ViewPager
?
How can I add a progress bar to a ViewPager
in Android?
我的情况是,我需要加载IMAGEURL在一个 ViewPager
。当用户刷寻呼机,如果没有装载IMAGEURL我需要显示进度条/加载GIF图像。
My scenario is that I have to load imageURL's in a ViewPager
. When the user swipes the pager, if the ImageURL is not loaded I need to show the progress bar/loading GIF image.
这可能吗?
推荐答案
我觉得萨蒂亚想在以下这样的事情。
在你viewpager适配器类,你应该有这样的方法:
I think Satya was thinking to something like this in the following.In your viewpager adapter class you should have this method:
@Override
public Object instantiateItem(View collection, final int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final FrameLayout imageLayout = (FrameLayout) inflater.inflate(R.layout.fotopager_buttons, null);
final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
imageLoader.displayImage(Gallery.get_big_image_url(position), imageView, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted() {
spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed() {
spinner.setVisibility(View.GONE);
imageView.setImageResource(android.R.drawable.ic_delete);
}
@Override
public void onLoadingComplete() {
spinner.setVisibility(View.GONE);
}
});
views.put(position, iv);
((ViewPager) collection).addView(imageLayout,0);
return imageLayout;
}
而R.layout.fotopager_buttons.xml这样的:
And the R.layout.fotopager_buttons.xml like that:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true" />
<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
您可以在这里看到的ImageLoader的类的其余部分:https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/UniversalImageLoaderExample/src/com/nostra13/example/universalimageloader/ImagePagerActivity.java
You can see the rest of the imageLoader class here: https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/UniversalImageLoaderExample/src/com/nostra13/example/universalimageloader/ImagePagerActivity.java
这篇关于如何进度栏添加到ViewPager Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!