如何在 android 中缩放相对布局(包含图像)?
How to zoom relative layout (contains images) in android?
我正在开发一个 android 应用程序,我已经在相对布局上设置了图像。现在我想通过手势(平移缩放)缩放图像,并且相对布局不包含任何图像视图。图片直接设置在相对布局上。
在我看来,缩放父级布局不是一个好习惯,因为它可能会造成复杂情况,但您可以找到可能的解决方案 zoom in/out RelativeLayout and this Github Gist 可能会在这方面对您有所帮助。
您的问题还有其他更好的解决方案,您可以创建一个具有 match_parent 属性的 ImageView
并使用 PhotoView 缩放图像,它用于缩放图像的惊人库,我我个人在我的多个项目中使用它。
这是 ImageView
和 match_parent
属性使用 PhotoView
。
<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>
您可以找到有关实现库的所有信息 here。
希望对您有所帮助
我正在开发一个 android 应用程序,我已经在相对布局上设置了图像。现在我想通过手势(平移缩放)缩放图像,并且相对布局不包含任何图像视图。图片直接设置在相对布局上。
在我看来,缩放父级布局不是一个好习惯,因为它可能会造成复杂情况,但您可以找到可能的解决方案 zoom in/out RelativeLayout and this Github Gist 可能会在这方面对您有所帮助。
您的问题还有其他更好的解决方案,您可以创建一个具有 match_parent 属性的 ImageView
并使用 PhotoView 缩放图像,它用于缩放图像的惊人库,我我个人在我的多个项目中使用它。
这是 ImageView
和 match_parent
属性使用 PhotoView
。
<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>
您可以找到有关实现库的所有信息 here。
希望对您有所帮助