使用第三方开源项目,地址: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>
本文介绍如何使用PhotoView开源项目加载并展示图片。通过继承ImageView并利用PhotoViewAttacher组件,可以轻松实现图片的缩放和平移功能。适用于Android应用开发。
1202

被折叠的 条评论
为什么被折叠?



