上效果:
Android 图片查看器Demo效果
- 导入PhotoView,导入Glide。
maven { url "https://jitpack.io" }
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
- 网络权限:
<uses-permission android:name="android.permission.INTERNET"/>
- 布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
- MainActivity.java 代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
Glide.with(MainActivity.this)
.load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202107%2F05%2F20210705100427_ee4b8.thumb.1000_0.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628415177&t=87962cc902fb5925da0a4d60d4c48ca9")
.into(photoView);
}
}