Pinch zooming on an image in Xamarin

。_饼干妹妹 提交于 2019-12-05 00:06:20

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/24351644/pinch-zooming-on-an-image-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!