2

What I'm trying to create is an ImageView scaleable and scrollable which also accepts large images. Currently I have this method in my overrided custom ImageView:

public void setLargeImageFromResource(int imageResource){
        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 10;
        Bitmap bitm = 
        BitmapFactory.decodeResource(getContext().getResources(), 
        imageResource, options);
        super.setImageBitmap(bitm);
}

I call it in my constructor like so:

public TouchImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TouchImageView, defStyle, 0);
        int base = a.getResourceId(R.styleable.TouchImageView_imageDrawable, R.drawable.kaart);
        setLargeImageFromResource(base);
    }

My Layout XML looks like this:

<nl.raakict.android.util.TouchImageView
    android:id="@+id/plattegrond"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    imageDrawable="@drawable/kaart"
 />

And my attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="TouchImageView">
        <attr name="imageDrawable" format="string"/>
  </declare-styleable>
</resources>
Bart Burg
  • 4,786
  • 7
  • 52
  • 87
  • Is this what you want to do: http://stackoverflow.com/questions/2537238/how-can-i-get-zoom-functionality-for-images/7458910#7458910 – luiscosta May 08 '14 at 09:15
  • I am actually using his class as base. It doesn't support large images though. That's what I'm trying to implement – Bart Burg May 08 '14 at 09:18
  • You can also use a WebView from the same post: http://stackoverflow.com/a/2538606/3465623 – luiscosta May 08 '14 at 09:31
  • That's what I had before. It was ok, but I didn't like the controls and the way it handles pinch zoom – Bart Burg May 08 '14 at 09:43

0 Answers0