Skip to content

Instantly share code, notes, and snippets.

@webserveis
Created April 18, 2017 11:47
Show Gist options
  • Save webserveis/67db2acce21b6d0d22b8f4c1511283bd to your computer and use it in GitHub Desktop.
Save webserveis/67db2acce21b6d0d22b8f4c1511283bd to your computer and use it in GitHub Desktop.
Crear un visor de imágenes en Android

Tutorial de como crear un visor de imágen en Android, con las propiedades:

  • Carga de imágen desde un recurso en internet
  • Poder hacer zoom con el gesto pellizcar
  • Al ampliar la imágen que se pueda moverse en ella
  • Que se auto ajuste a la pantalla, con doble toque o haga un pequeño zoom
  • Compatible en rotar el dispositivo

Preparativos

Principalmente se usará dos librerías Glide y la XuaniImageView

compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.allenxuan:xuanimageview:0.4.0'

Creación del Layout y Tema

Definición en styles.xml

    <style name="AppTheme.DisplayImage" parent="Theme.AppCompat">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:animateLayoutChanges="true"
    tools:context="com.webserveis.app.testtransitions.PhotoViewActivity">

    <com.webserveis.app.testtransitions.PhotoImageView
        android:id="@+id/iv_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/dummy_image"
        app:AutoRotateCategory="2" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#88676767"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</RelativeLayout>

Controlador

Interceptar los gestos sobre la imágen

Podemos interceptar los gestos sobre el componente xuaniImageView y delegar cual queremos para poderlo usar en el código principal.

Extras

Aplicar que la barra ActionBar se auto oculte despues de un tiempo y se vuelve a mostrar al hacer toque sobre la imágen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment