Skip to content

campusappcn/LongImageView

Repository files navigation

LongImageView

A view to show long image (like weibo).

Features:

  1. Long/HUGE image display + scroll
  2. Double click to zoom in/out
  3. Pinch to zoom in/out

Usage:

<?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">

    <!-- set drawable from xml -->
    <cn.campusapp.longimageview.LongImageView
        android:id="@+id/long_image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:src="@drawable/some_drawable"/>
</RelativeLayout>
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final LongImageView liv = (LongImageView) findViewById(R.id.long_image_view);
        // 1. set drawable resource id
        liv.setImage(R.drawable.some_drawable);
        // 2. set input stream
        liv.setImage(getAssets().open("some_picture.jpg")); // only supports "jpg"/"jpeg" and "png" format
        // 3. set bitmap
        liv.setImage(/* a bitmap*/);
        // 4. set file
        liv.setImage(new File("/data/local/tmp/some_image.jpg"));
        // 5. set drawable
        liv.setImage(ContextCompat.getDrawable(this, R.drawable.some_drawable));
        // 6. set path
        liv.setImage("/data/local/tmp/some_image.jpg");
    }
}

Add dependency:

    allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

    dependencies {
        compile 'com.github.campusappcn:LongImageView:1.3.0'
    }