Search code examples
javaandroidzoomingandroid-relativelayout

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


I am developing an android app and I have set images on relative layout. Now I want to zoom the images through gestures (pan zoom) and the relative layout doesn't contain any imageview. The images are directly set on the relative layout.


Solution

  • Well in my openion its not a good practice to zoom the parent layout as it might create complications but you can find the possible solutions zoom in/out RelativeLayout and this Github Gist might help you in this regard.

    Othere better solution to your problem can be you can create an ImageView with match_parent attributes and use PhotoView to zoom the images, its amazing library for zooming the images, I am personally using it in my multiple projects.

    This is the ImageView with match_parent attributes using 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>
    

    You can find all the information about implementing the library here.

    Hope it helps