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
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'
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>
Podemos interceptar los gestos sobre el componente xuaniImageView
y delegar cual queremos para poderlo usar en el código principal.
Aplicar que la barra ActionBar
se auto oculte despues de un tiempo y se vuelve a mostrar al hacer toque sobre la imágen.