我是android的新手。什么是最简单的方法将图像视图弹出全屏(启用了捏缩放),当它被点击时,就像whatsapp图像一样?我正在通过Glide在回收站视图中加载我的图像。感谢您的时间和回复。
答案 0 :(得分:7)
有一个名为StfalconImageViewer的库。它支持开箱即用的过渡动画,用于图像的打开和关闭,捏合缩放和滑动消除手势。使用Glide可以做到:
new StfalconImageViewer.Builder<>(context, images, new ImageLoader<String>() {
@Override
public void loadImage(ImageView imageView, String imageUrl) {
Glide.with(context).load(imageUrl).into(imageView)
}
}).show();
希望这会有所帮助!
答案 1 :(得分:2)
您可以使用ImageView
视图,其比例类型为FIT_XY
(有关ImageView
here的比例类型的详情,请参阅
答案 2 :(得分:2)
我使用了PhotoView(https://github.com/chrisbanes/PhotoView)和Glide(https://github.com/bumptech/glide)。
我首先创建了全屏活动,然后将PhotoView放置在布局中。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="#000000"
tools:context=".PhotoviewerActivity">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
然后,我将要显示的图像URL传递给全屏活动,并使用Glide加载图像,如下所示。
val imageUrl = intent.getStringExtra(IMAGE_URL)
Glide.with(applicationContext).load(imageUrl).into(fullscreen_content)
您可以从全屏布局中删除所有不需要的代码,也可以从全屏活动代码中禁用它。 这些代码是用Kotlin编写的。
答案 3 :(得分:0)
这是我对单个图像和使用滑行的工作代码。最后,我发现了与WhatsApp类似的东西。我在互联网上搜寻了三天,现在我找到了解决方案。
new StfalconImageViewer.Builder<String>(context, new ArrayList<>(Arrays.asList(messageModel.get(position).getUrl().trim())), new ImageLoader<String>() {
@Override
public void loadImage(ImageView imageView, String image) {
Glide.with(context)
.load(image)
.into(imageView);
}
}).show();