Android 美国毕加索公司关于ViewPager的问题

Android 美国毕加索公司关于ViewPager的问题,android,Android,我有一个代码,图像将显示在ViewPager上,图像将来自服务器。我使用的是毕加索图书馆,但当我使用毕加索时,图像不会出现在ViewPager上。数组图像有图像的URL,我在加载方法中添加了该URL,请检查我的代码并向我建议问题。下面是XML和java代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:

我有一个代码,图像将显示在ViewPager上,图像将来自服务器。我使用的是毕加索图书馆,但当我使用毕加索时,图像不会出现在ViewPager上。数组图像有图像的URL,我在加载方法中添加了该URL,请检查我的代码并向我建议问题。下面是XML和java代码

<RelativeLayout 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/image"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:layout_gravity="right|top" />

<ProgressBar android:id="@+id/progressBar"
    android:progressDrawable="@drawable/loader_image"
    android:layout_width="fill_parent" android:layout_height="8dip"
    style="?android:attr/progressBarStyleHorizontal"
    android:indeterminateOnly="false"
    android:max="100">
</ProgressBar>

公共类SlidingImage_适配器扩展了PagerAdapter{
私有数组列表图像;
私人停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场;
私人语境;
ProgressBar ProgressBar;
私有图像加载器;
公共幻灯片图像适配器(上下文、ArrayList图像){
this.context=上下文;
这个。图像=图像;

对于(inti=0;i试试这个。在代码中添加view.addView(item_view);

@Override
public Object instantiateItem(ViewGroup view, int position) {
  //  ImageView imageLayout = (ImageView) inflater.inflate(R.layout.screen_slide_fragment, view, false);
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View item_view = layoutInflater.inflate(R.layout.screen_slide_fragment, view, false);
    ImageView imageView = (ImageView) item_view.findViewById(R.id.image);
    Log.e("instantiateItem: ",IMAGES.get(position) );
    Picasso.with(context)
            .load(IMAGES.get(position))
            .error(R.drawable.girl)
            .placeholder(R.drawable.loader_image)
            .fit()
            .centerCrop()
            .into(imageView);

    //you need to add this line
    view.addView(item_view);

    return item_view;
}
要显示进度条,请使用下面的代码并编译

编译'com.github.bumptech.glide:glide:3.7.0'

进入应用程序渐变文件

public class SlidingImage_Adapter extends PagerAdapter {
private ArrayList<String> IMAGES;
private LayoutInflater layoutInflater;
private Context context;
ProgressBar progressBar;
private ImageLoader imageLoader;

public SlidingImage_Adapter(Context context, ArrayList<String> IMAGES) {
    this.context = context;
    this.IMAGES=IMAGES;
}


@Override
public Object instantiateItem(ViewGroup view, int position) {
  //  ImageView imageLayout = (ImageView) inflater.inflate(R.layout.screen_slide_fragment, view, false);
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View item_view = layoutInflater.inflate(R.layout.screen_slide_fragment, view, false);
    ImageView imageView = (ImageView) item_view.findViewById(R.id.image);
    Log.e("instantiateItem: ",IMAGES.get(position) );

    ProgressBar spinner = (ProgressBar) item_view.findViewById(R.id.progressBar);

    //This will help to load image and show progressBar
    imageLoader = new ImageLoader(imageView, spinner, IMAGES.get(position));

    //you need to add this line
    view.addView(item_view);

    return item_view;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((View) object);
}

@Override
public int getCount() {
    return IMAGES.size();
}


@Override
public boolean isViewFromObject(View view, Object object) {
    return view.equals(object);

}

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
}

@Override
public Parcelable saveState(){
    return null;
   }



    public class ImageLoader{

        public ImageLoader(ImageView imageView, final ProgressBar progressBar, String imagePath){

            Glide.with(context).load(imagePath).listener(new RequestListener<String, GlideDrawable>() {

                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    //handle error
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    progressBar.setVisibility(View.GONE);
                    return false;
                }
            }).into(imageView);
        }
    }

}
公共类SlidingImage_适配器扩展了PagerAdapter{
私有数组列表图像;
私人停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场;
私人语境;
ProgressBar ProgressBar;
私有图像加载器;
公共幻灯片图像适配器(上下文、ArrayList图像){
this.context=上下文;
这个。图像=图像;
}
@凌驾
公共对象实例化项(视图组视图,int位置){
//ImageView imageLayout=(ImageView)充气器。充气(R.layout.screen\u slide\u片段,视图,false);
layoutInflater=(layoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
视图项\u视图=布局平坦。充气(R.layout.screen\u slide\u片段,视图,假);
ImageView ImageView=(ImageView)项_view.findViewById(R.id.image);
Log.e(“实例化项:”,IMAGES.get(位置));
ProgressBar微调器=(ProgressBar)项_视图.findViewById(R.id.ProgressBar);
//这将有助于加载图像并显示progressBar
imageLoader=新的imageLoader(imageView、微调器、IMAGES.get(position));
//您需要添加这一行
视图。添加视图(项目视图);
返回项目视图;
}
@凌驾
公共项(视图组容器、int位置、对象){
container.removeView((视图)对象);
}
@凌驾
public int getCount(){
返回图像。size();
}
@凌驾
公共布尔值isViewFromObject(视图,对象){
返回视图.equals(对象);
}
@凌驾
公共无效恢复状态(可包裹状态,类装入器){
}
@凌驾
公共包裹存储状态(){
返回null;
}
公共类图像加载器{
公共ImageLoader(ImageView ImageView、最终ProgressBar ProgressBar、字符串imagePath){
Glide.with(context.load(imagePath.listener)(newrequestlistener()){
@凌驾
公共布尔onException(异常e、字符串模型、目标、布尔isFirstResource){
//处理错误
返回false;
}
@凌驾
公共布尔值onResourceReady(GlideDrawable资源、字符串模型、目标、布尔值isFromMemoryCache、布尔值isFirstResource){
progressBar.setVisibility(View.GONE);
返回false;
}
}).进入(图像视图);
}
}
}
xml文件代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:padding="1dip" >

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:max="100"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_gravity="right|top"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

试试这个。在代码中添加视图。添加视图(项目视图);

@Override
public Object instantiateItem(ViewGroup view, int position) {
  //  ImageView imageLayout = (ImageView) inflater.inflate(R.layout.screen_slide_fragment, view, false);
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View item_view = layoutInflater.inflate(R.layout.screen_slide_fragment, view, false);
    ImageView imageView = (ImageView) item_view.findViewById(R.id.image);
    Log.e("instantiateItem: ",IMAGES.get(position) );
    Picasso.with(context)
            .load(IMAGES.get(position))
            .error(R.drawable.girl)
            .placeholder(R.drawable.loader_image)
            .fit()
            .centerCrop()
            .into(imageView);

    //you need to add this line
    view.addView(item_view);

    return item_view;
}
要显示进度条,请使用下面的代码并编译

编译'com.github.bumptech.glide:glide:3.7.0'

进入应用程序渐变文件

public class SlidingImage_Adapter extends PagerAdapter {
private ArrayList<String> IMAGES;
private LayoutInflater layoutInflater;
private Context context;
ProgressBar progressBar;
private ImageLoader imageLoader;

public SlidingImage_Adapter(Context context, ArrayList<String> IMAGES) {
    this.context = context;
    this.IMAGES=IMAGES;
}


@Override
public Object instantiateItem(ViewGroup view, int position) {
  //  ImageView imageLayout = (ImageView) inflater.inflate(R.layout.screen_slide_fragment, view, false);
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View item_view = layoutInflater.inflate(R.layout.screen_slide_fragment, view, false);
    ImageView imageView = (ImageView) item_view.findViewById(R.id.image);
    Log.e("instantiateItem: ",IMAGES.get(position) );

    ProgressBar spinner = (ProgressBar) item_view.findViewById(R.id.progressBar);

    //This will help to load image and show progressBar
    imageLoader = new ImageLoader(imageView, spinner, IMAGES.get(position));

    //you need to add this line
    view.addView(item_view);

    return item_view;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((View) object);
}

@Override
public int getCount() {
    return IMAGES.size();
}


@Override
public boolean isViewFromObject(View view, Object object) {
    return view.equals(object);

}

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
}

@Override
public Parcelable saveState(){
    return null;
   }



    public class ImageLoader{

        public ImageLoader(ImageView imageView, final ProgressBar progressBar, String imagePath){

            Glide.with(context).load(imagePath).listener(new RequestListener<String, GlideDrawable>() {

                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    //handle error
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    progressBar.setVisibility(View.GONE);
                    return false;
                }
            }).into(imageView);
        }
    }

}
公共类SlidingImage_适配器扩展了PagerAdapter{
私有数组列表图像;
私人停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场;
私人语境;
ProgressBar ProgressBar;
私有图像加载器;
公共幻灯片图像适配器(上下文、ArrayList图像){
this.context=上下文;
这个。图像=图像;
}
@凌驾
公共对象实例化项(视图组视图,int位置){
//ImageView imageLayout=(ImageView)充气器。充气(R.layout.screen\u slide\u片段,视图,false);
layoutInflater=(layoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
视图项\u视图=布局平坦。充气(R.layout.screen\u slide\u片段,视图,假);
ImageView ImageView=(ImageView)项_view.findViewById(R.id.image);
Log.e(“实例化项:”,IMAGES.get(位置));
ProgressBar微调器=(ProgressBar)项_视图.findViewById(R.id.ProgressBar);
//这将有助于加载图像并显示progressBar
imageLoader=新的imageLoader(imageView、微调器、IMAGES.get(position));
//您需要添加这一行
视图。添加视图(项目视图);
返回项目视图;
}
@凌驾
公共项(视图组容器、int位置、对象){
container.removeView((视图)对象);
}
@凌驾
public int getCount(){
返回图像。size();
}
@凌驾
公共布尔值isViewFromObject(视图,对象){
返回视图.equals(对象);
}
@凌驾
公共无效恢复状态(可包裹状态,类装入器){
}
@凌驾
公共包裹存储状态(){
返回null;
}
公共类图像加载器{
公共ImageLoader(ImageView ImageView、最终ProgressBar ProgressBar、字符串imagePath){
Glide.with(context.load(imagePath.listener)(newrequestlistener()){
@凌驾
公共布尔onException(异常e、字符串模型、目标、布尔isFirstResource){
//处理错误
返回false;
}
@凌驾
公共布尔值onResourceReady(GlideDrawable资源、字符串模型、目标、布尔值isFromMemoryCache、布尔值isFirstResource){
progressBar.setVisibility(View.GONE);
返回false;
}
}).进入(图像视图);
}
}
}