androidimageviewandroid-volleynetworkimageviewscaletype

ScaleType in ImageView not working


I am trying to make a gallery of images using ViewPager and Volley's NetworkImageView. Everything is working fine with the viewpager and image retrieve. But when i put the bitmap in the NetworkImageView, the image is not stretched to fill the size of the NetworkImageView. With my other ImageView, setting the scaleType works just fine.

<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY" />

My xml file

public static class SwipeFragment extends Fragment {

    ImageLoader imageLoader = AppController.getInstance().getImageLoader();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View swipeView = inflater.inflate(R.layout.swipe_fragment, container, false);
        NetworkImageView imageView = (NetworkImageView) swipeView.findViewById(R.id.imageView);
        Bundle bundle = getArguments();
        int position = bundle.getInt("position");
        if (imageLoader == null) {
            imageLoader = AppController.getInstance().getImageLoader();
        }
        imageView.setImageUrl(fotoUrl.get(position), imageLoader);
        return swipeView;

    }

    static SwipeFragment newInstance(int position) {
        SwipeFragment swipeFragment = new SwipeFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        swipeFragment.setArguments(bundle);
        return swipeFragment;
    }
}

My java

Any idea about this problem? I have also tried to change the scaleType into fitCenter but still the same results. Thank you in advance.


Solution

  • I think your issue is because of the wrap_content values used for width and height. Try to use the below code and it should work.

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/imageView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:scaleType="fitXY" />
    

    When you say wrap_content that means you are asking view to be of same height and width of the image hence scaling doesn't apply. When you fix the width and height then you can apply fitXY scale type.