In Xamarin
, what is the best way to enable pinch zooming for an image? Currently I have just an ImageView
that has a Bitmap
image as an image.
I have done some research, and I have found a few examples where people have used some other libraries but would like some advice on the best way to enable pinch zooming on an image before I start writing this code.
So, what is the best way to enable pinch zooming on an image in Android
, specifically Xamarin
?
Thank in advance
You can get ImageView zoom-in capabilities and panning of the zoomed in image by using the Monodroidtoolkit ScaleImageView.
First, add the ScaleImageView.cs class to your project using the code from here.
The toolkit also has a sample of how to use it, basically you add an activity like this:
namespace Samples
{
[Activity(Label = "My Activity")]
public class ScaleImageActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ScaleImage);
}
}
}
Then, add the ScaleImage.axml layout by creating a layout with the following XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.refractored.monodroidtoolkit.ScaleImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/seattle"
android:id="@+id/AnimateImage">
</com.refractored.monodroidtoolkit.ScaleImageView>
</LinearLayout>
Finally, in this sample it is loading an image of Seattle from the drawable folder, so add the seattle.jpg image which can be found here
The MonoDroidToolkit has a project with a bunch of samples including this one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With