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>