繁体   English   中英

如何在android中缩放相对布局(包含图像)?

[英]How to zoom relative layout (contains images) in android?

我正在开发一个Android应用,并且已经在相对布局上设置了图像。 现在,我想通过手势缩放图像(平移缩放),并且相对布局不包含任何imageview。 图像直接设置在相对布局上。

在我看来,缩放父级布局不是一个好习惯,因为它可能会带来麻烦,但是您可以找到放大/缩小RelativeLayout的可能解决方案而这个Github Gist可能会在这方面为您提供帮助。

要解决您的问题,更好的解决方案是您可以创建具有match_parent属性的ImageView并使用PhotoView缩放图像,它的惊人的库可以缩放图像,我个人在多个项目中都使用了它。

这是具有使用PhotoView match_parent属性的ImageView

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <uk.co.senab.photoview.PhotoView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"/>

</RelativeLayout>

您可以在此处找到有关实现该库的所有信息。

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM