tag | 5a3be3285abe435c7b580f9846a53a29ced43418 | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Tue Mar 23 00:03:11 2021 -0700 |
object | 5fb46aa47bd8d0ca763b7f17033a6f842e57d4f9 |
Android Mainline 11.0.0 Release 6 (7124067)
commit | 5fb46aa47bd8d0ca763b7f17033a6f842e57d4f9 | [log] [tgz] |
---|---|---|
author | Xin Li <delphij@google.com> | Mon Dec 10 12:53:09 2018 -0800 |
committer | android-build-merger <android-build-merger@google.com> | Mon Dec 10 12:53:09 2018 -0800 |
tree | fea66d74c8b32d168fc354d281a68937c582a928 | |
parent | 45ca08280baebd7342764bdbc9b520d7183d6ad7 [diff] | |
parent | 4a9a0dc8adf43212b275d4db36a4ddee2e994240 [diff] |
[automerger skipped] DO NOT MERGE am: 5ffef6ff20 -s ours am: 75a004caa3 -s ours am: 4a9a0dc8ad -s ours Change-Id: I5a28dee317c0af65ed4881cfc66ee308cad19100
A custom image view for Android, designed for photo galleries and displaying huge images (e.g. maps and building plans) without OutOfMemoryError
s. Includes pinch to zoom, panning, rotation and animation support, and allows easy extension so you can add your own overlays and touch event detection.
The view optionally uses subsampling and tiles to support very large images - a low resolution base layer is loaded and as you zoom in, it is overlaid with smaller high resolution tiles for the visible area. This avoids holding too much data in memory. It's ideal for displaying large images while allowing you to zoom in to the high resolution details. You can disable tiling for smaller images and when displaying a bitmap object. There are some advantages and disadvantages to disabling tiling so to decide which is best, see the wiki.
Versions 3.9.0, 3.8.0 and 3.0.0 contain breaking changes. Migration instructions can be found in the wiki.
With tiling enabled:
OnClickListener
and OnLongClickListener
GestureDetector
and OnTouchListener
ViewPager
to create a photo gallerywrap_content
layout1) Add com.davemorrissey.labs:subsampling-scale-image-view:3.9.0
as a dependency in your build.gradle file.
2) Add the view to your layout XML.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout>
3a) Now, in your fragment or activity, set the image resource, asset name or file path.
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView); imageView.setImage(ImageSource.resource(R.drawable.monkey)); // ... or ... imageView.setImage(ImageSource.asset("map.png")) // ... or ... imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
3b) Or, if you have a Bitmap
object in memory, load it into the view. This is unsuitable for large images because it bypasses subsampling - you may get an OutOfMemoryError
.
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView); imageView.setImage(ImageSource.bitmap(bitmap));
Copyright 2018 David Morrissey, and licensed under the Apache License, Version 2.0. No attribution is necessary but it's very much appreciated. Star this project if you like it!