现在的位置: 首页 > 综合 > 正文

Android使用PhotoView实现图片缩放功能

2016年05月24日 ⁄ 综合 ⁄ 共 765字 ⁄ 字号 评论关闭

使用第三方开源项目,地址:https://github.com/chrisbanes/PhotoView

 

引入library 项目.

简单的加载一张图片:

public class MainActivity extends Activity {

	ImageView imgView;
	PhotoViewAttacher attacher; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		imgView=(ImageView) findViewById(R.id.img);
		imgView.setImageResource(R.drawable.wallpaper);
		attacher=new PhotoViewAttacher(imgView);
	}
}

布局文件:

<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=".MainActivity" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/img" />

</RelativeLayout>

 

抱歉!评论已关闭.