使用第三方开源项目,地址: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>