Java 在Android中如何在PagerView中设置全幅图像?

Java 在Android中如何在PagerView中设置全幅图像?,java,android,android-layout,android-fragments,Java,Android,Android Layout,Android Fragments,我想在此ImagePagerView中设置全宽图像。每一张图片都将是全宽和全高的,以便在每一页中查看。请提供任何帮助。下面给出了Java代码。请帮忙 package com.exampe.imagepager; public class FragmentImageView extends Fragment { package com.exampe.imagepager; public class FragmentImageView extends Fragment { private In

我想在此ImagePagerView中设置全宽图像。每一张图片都将是全宽和全高的,以便在每一页中查看。请提供任何帮助。下面给出了Java代码。请帮忙

package com.exampe.imagepager;

public class FragmentImageView extends Fragment {
package com.exampe.imagepager;

public class FragmentImageView extends Fragment {

private Integer itemData;
private Bitmap myBitmap;
public ProgressDialog pd;
private ImageView ivImage;

public static FragmentImageView newInstance() {
    FragmentImageView f = new FragmentImageView();
    return f;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@SuppressWarnings("deprecation")
@Override
public View onCreateView

(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 

{

    View root = inflater.inflate(R.layout.imageview, container, false);

    ivImage = (ImageView) root.findViewById(R.id.ivImageView);

    setImageInViewPager();

    return root;
}

public void setImageList(Integer integer) {
    this.itemData = integer;
}

public void setImageInViewPager() {

    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        myBitmap = BitmapFactory.decodeResource(getResources(), itemData,
                options);
        if (options.outWidth > 3000 || options.outHeight > 2000) {
            options.inSampleSize = 4;
        } else if (options.outWidth > 2000 || options.outHeight > 1500) {
            options.inSampleSize = 3;
        } else if (options.outWidth > 1000 || options.outHeight > 1000) {
            options.inSampleSize = 2;
        }
        options.inJustDecodeBounds = false;
myBitmap = BitmapFactory.decodeResource(getResources(), itemData,options);

if (myBitmap != null) {
            try {
                if (ivImage != null) {
                    ivImage.setImageBitmap(myBitmap);
                }
            } 

            catch (Exception e) {
                e.printStackTrace();
            }
        }
    } 
    catch (OutOfMemoryError e) {
        e.printStackTrace();
        System.gc();
    }
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    if (myBitmap != null) {
        myBitmap.recycle();
        myBitmap = null;
    }


 }
}
Xml代码是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
 >

 <ImageView
  android:id="@+id/ivImageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

 </LinearLayout>

例如,您可以使用:

<ImageView
    android:id="@+id/ivImageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop" />