Question

I have a VerticalViewPager and I have some images in it. When I rotate my device in landscape mode my ImageView doesn't scale to width of my screen. It fits the height if image instead. I used AspectRatioImageView. It fits the width but VerticalViewPager doesn't scroll down. Thank you.

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<HackyViewPager
    android:id="@+id/vvp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    >
</HackyViewPager>
</RelativeLayout>

Here is rowitemview.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#fff" >
    <AspectRatioImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/m4_3" />
</LinearLayout>

and here is my instaniateItem of my ImagePageAdapter that extends PagerAdapter:

@Override
    public Object instantiateItem(ViewGroup container, int position) 
    {
        Context context = MainActivity.this;

        container.requestLayout();
          AspectRatioImageView imageView = new     AspectRatioImageView(context);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.m4_3));


          mAttacher = new PhotoViewAttacher(imageView);
          mAttacher.setOnMatrixChangeListener(new OnMatrixChangedListener() {

            @Override
            public void onMatrixChanged(RectF rect) {
                if((int)rect.width()>_width)
                    viewPager.setLocked(true);
                else
                    viewPager.setLocked(false);
            }
        });

P.S : The issue is with viewPager height. When I scroll down the image it just goes to the other page instead of scrolling the scaled image.

Was it helpful?

Solution

Here's what you need.

This is a good solution I found out.

Android Crop Center of Bitmap

This allows to set the height and your width according to your orientation.

To change the image's scale to full screen, you generally use center crop like this:

yourImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

Hope this information was useful..:)

OTHER TIPS

Use android:scalType = "fitxy" in activity code like this imageView.setScaleType(ImageView.ScaleType.FIT_XY);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top