仿今日头条中图片的缩放处理。PhotoView是一个第三方的图片处理框架,支持图片的缩放。
GitHub地址:https://github.com/chrisbanes/PhotoView
另外一个: https://github.com/bm-x/PhotoView
PhotoView特性:
1.支持放缩超出边界,多点触控和双击事件
2.滚动和滑动
3.和ViewPager等能完美兼容
4.矩阵变化等有回调,方便前台其他展示的改变
5.单击,长按都有回调提醒
PhotoView使用:
1.首先在Github下载PhotoView框架。
2.打开PhotoView-master,找到里面的library
3.将library里面的内容,如下:复制到项目中
至此,就可以使用PhotoView实现图片的缩放了:
public class MainActivity extends AppCompatActivity{xml文件:
private ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.image);
Drawable bitmap = getResources().getDrawable(R.drawable.img00);
mImageView.setImageDrawable(bitmap);
PhotoViewAttacher mAttacher = new PhotoViewAttacher(mImageView);
}
}
<?xml version="1.0" encoding="utf-8"?>其中,对图片缩放的倍数,可以自己更改,设置在类IPhotoView中:
<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="com.example.administrator.myphotoview.MainActivity">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
当该框架和ViewPage结合使用时,可参考网址:zhanglu0574.blog.163.com/blog/static/1136510732014111643144323/
效果图: