PhotoView图片的缩放与滑动

1、使用到的依赖是:
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.picasso:picasso:2.5.1'
两者皆可,都是图片的加载框架。
2.这是photoView的jar,可以自行下载一下。
3.代码:
//这是传递的集合,点击进行跳转,将图片的集合传过去。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
Intent in=new Intent(MainActivity.this,NextActivity.class);
in.putStringArrayListExtra("list",list);
startActivity(in);
}
});
4:接收到了传过来的值,并设置给fragment的参数,viewPager适配时采用FragmentPagerAdapter的适配器。
public class NextActivity extends AppCompatActivity {

private ArrayList list;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. next_layout );
Intent intent = getIntent();
list = intent.getStringArrayListExtra("list");
ViewPager viewPager= (ViewPager) findViewById(R.id. viewPager_next );
// 设置适配器
viewPager.setAdapter(new FragAdapter(getSupportFragmentManager()));
}
private class FragAdapter extends FragmentPagerAdapter{

public FragAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
FragmentNext f1=new FragmentNext();
Bundle bundle = new Bundle();//通过bundle传值的方式
bundle.putString("imageUrl",list.get(position));
f1.setArguments(bundle);
return f1;
}

@Override
public int getCount() {
return list.size();
}
}
}
5:在fragment中的设置图片的缩放
public class FragmentNext extends Fragment {

private View view;


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout. frag_layout ,null);

return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
PhotoView photo= (PhotoView) view.findViewById(R.id. pv );
//拿到参数
Bundle bundle = getArguments();
String image = bundle.getString("imageUrl");
//设置图片
Glide. with (this).load(image).into(photo);
// 设置监听
photo.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float v, float v1) {
getActivity().finish();
}
});
}
}

你可能感兴趣的:(PhotoView图片的缩放与滑动)