简体   繁体   中英

how to make photoview library work with viewpager

I am new to android development. I am using photoview library to enable zooming of images in my imageviewer app. But viewpager and zooming ability are not working at the same time.When I include photoView.setVisibility(View.GONE); in FullImageActivity.java , viewpager starts working and when I remove it, zooming ability starts working. But both zooming and viewpager do not work at the same time. How do I fix this ? Thanks

Full code is available at https://github.com/redviper00/game

FullImageActivity.java :

public class FullImageActivity extends AppCompatActivity {
    int position;
    int folderPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_image);
        Intent i = getIntent();
        PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
        photoView.setVisibility(View.GONE);

        // Selected image id
        position = i.getExtras().getInt("id");
        folderPosition = i.getExtras().getInt("folderPosition");
        Bundle extras = getIntent().getExtras();
        String value = extras.getString("abc");

        Glide.with(FullImageActivity.this)
                .load(value)
                .skipMemoryCache(false)
                .into(photoView);

        ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mViewPager.setAdapter(new TouchImageAdapter(this,al_images, folderPosition));
        mViewPager.setCurrentItem(position);
    }
}

activity_full_image.xml :

<?xml version="1.0" encoding="utf-8"?>

     <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/jazzy_pager"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

     <com.github.chrisbanes.photoview.PhotoView
         android:id="@+id/photo_view"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="center"
         android:scaleType="centerCrop"/>

     <android.support.v4.view.ViewPager
         android:id="@+id/viewpager"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

</LinearLayout>

give custom "android:layout_height" to view pager and PhotoView so it will work for u.........

You have given both match parent so it is not working......

You are not using Imageview inside your adapter eg : TouchImageAdapter. You should use PhotoView Object, and your issue will resolved.

 PhotoView img = new PhotoView(container.getContext());

Please have a look at code changes which I pushed to your repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM