Search code examples
androidimageviewzoomingscrollview

Use of Zoom in ImageView inside ScrollView


I'm trying to use zoom in an ImageView. I've searched and tried so many codes but the problem is that I have ImageView inside an ScrollView because I have some other objects.

This is the last code if tried.

And here is xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    tools:context=".ConsumoActivity"
    android:orientation="vertical" >

    <LinearLayout 
        android:id="@+id/linearLayoutLogoFactor_consumo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <ImageView 
            android:id="@+id/imageViewLogoFactor_consumo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo_factorenergia" />

    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollViewConsumo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >

        <LinearLayout
            android:id="@+id/linearLayoutConsumo2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_gravity="center_horizontal"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical" >

            <TextView 
                android:id="@+id/textViewVerConsumo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:text="@string/etiqueta_ver_consumo"
                android:textSize="@dimen/textSize"
                android:layout_marginTop="10dp"
                android:textStyle="italic"
                android:textColor="#79b7e3" />

            <LinearLayout 
                android:id="@+id/linearLayoutDireccionConsumo"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="10dp"
                android:weightSum="1.0">

                <TextView
                    android:id="@+id/textViewlabelDireccionConsumo"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.3"
                    android:text="@string/etiqueta_direccion"
                    android:textSize="@dimen/textSize"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textViewDireccionConsumo"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.7"
                    android:textSize="@dimen/textSize" />

            </LinearLayout>

            <com.example.factorenergia.CustomImageView
                android:id="@+id/imageViewConsumo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="15dp"
                android:adjustViewBounds="true" 
                android:scaleType="matrix" />

            <RelativeLayout
                android:id="@+id/linearLayoutImagenInferior_consumo"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginTop="20dp" >

                <ImageView
                    android:id="@+id/imageViewImagenInferior_consumo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:adjustViewBounds="true"
                    android:src="@drawable/la_electrica_de_las_empresas" />
            </RelativeLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

Image is ok but scroll is not working. Is there any way for solving that having ImageView inside ScrollView with some other objects?


Solution

  • I've used an easy solution:

    Let my layout as it was and when ImageView is clicked, go to a new one which only has the Image, using Mike Ortiz code at that question.