lets use subsampling-scale-image-view for proper zooming
This commit is contained in:
parent
e38ac2893d
commit
42ba6b0e1d
5 changed files with 54 additions and 30 deletions
|
@ -24,5 +24,5 @@ dependencies {
|
|||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'com.github.bumptech.glide:glide:3.7.0'
|
||||
compile 'com.commit451:PhotoView:1.2.4'
|
||||
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1'
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package gallery.simplemobiletools.com;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.ImageSource;
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||
|
||||
public class ViewPagerFragment extends Fragment {
|
||||
private String path;
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.pager_item, container, false);
|
||||
|
||||
if (path != null) {
|
||||
final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo);
|
||||
imageView.setImage(ImageSource.uri(path));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
|
@ -26,7 +26,8 @@ public class ViewPagerActivity extends AppCompatActivity {
|
|||
|
||||
pos = 0;
|
||||
final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager);
|
||||
final MyPagerAdapter adapter = new MyPagerAdapter(this, getPhotos());
|
||||
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
|
||||
adapter.setPaths(getPhotos());
|
||||
pager.setAdapter(adapter);
|
||||
pager.setCurrentItem(pos);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
package gallery.simplemobiletools.com.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import uk.co.senab.photoview.PhotoView;
|
||||
import gallery.simplemobiletools.com.ViewPagerFragment;
|
||||
|
||||
public class MyPagerAdapter extends PagerAdapter {
|
||||
private final Context context;
|
||||
private final List<String> paths;
|
||||
public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
||||
private List<String> paths;
|
||||
|
||||
public MyPagerAdapter(Context context, List<String> paths) {
|
||||
this.context = context;
|
||||
public MyPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
public void setPaths(List<String> paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
|
@ -26,21 +25,9 @@ public class MyPagerAdapter extends PagerAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
final PhotoView photoView = new PhotoView(context);
|
||||
Glide.with(context).load(paths.get(position)).fitCenter().crossFade().into(photoView);
|
||||
container.addView(photoView);
|
||||
photoView.setMaximumScale(20f);
|
||||
return photoView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
container.removeView((View) object);
|
||||
public Fragment getItem(int position) {
|
||||
final ViewPagerFragment fragment = new ViewPagerFragment();
|
||||
fragment.setPath(paths.get(position));
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
|
6
app/src/main/res/layout/pager_item.xml
Normal file
6
app/src/main/res/layout/pager_item.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
android:id="@+id/photo"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
Loading…
Reference in a new issue