Android 图片点击放大缩小手势操作以及解决Viewpager左右滑动与ImageView手势冲突导致左右滑动失效问题
在我的项目中,有点击图片banner后放大浏览的功能。我的做法就是创建一个专门的图片显示Activity,布局里面用ViewPage,这样就能控制图片的左右滑动,并且控制首先显示第几张图片。
功能是ok的,显示也是正常的。但我花费了好几天的时间来实现、完善这个功能。
ShowMoreImageActivity
/**
* 图片放大
*/
public class ShowMoreImageActivity extends BaseActivity {
@FindId(R.id.vp)
private ViewPager vp;
@FindId(R.id.ll_point)
private LinearLayout ll_point;
private List<String> imgs;
@FindId(R.id.btn_save)
private ImageView btn_save;
private int index;
public static int type;
private Activity activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_more_image);
initViews();
activity = this;
}
private void initViews() {
AutoFindId.findId(context);
imgs = (ArrayList<String>) getIntent().getSerializableExtra("img");
index = getIntent().getIntExtra("index", 0);
type = getIntent().getIntExtra("type", 0);
vp.setAdapter(new MoreImgPagerAdapter(context, imgs));
vp.addOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
index = arg0;
setUpPoint(imgs.size(), arg0);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
setUpPoint(imgs.size(), 0);
vp.setCurrentItem(index);
}
protected void downLoad(final String urls) {
String[] split = urls.split("\\?");
final String url = split[0];
if (url.startsWith("file")) {
G.toast(context, "此为本地图片,不用下载,路径为" + url.replace("file://", ""));
return;
}
if (OKHttpUtils.isNetworkAvailable(context)) {
G.showPd(context);
TDUtils.execute(new Runnable() {
@Override
public void run() {
try {
File file = new File(C.getDownloadPath());
if (!file.exists()) {
file.mkdir();
}
File jpg = new File(C.getDownloadPath() + G.urlToFileName(url));
// 如果已经存在则不需要下载
if (jpg != null && jpg.exists()) {
G.dismissProgressDialogInThread();
G.toastInThread(context,
<