2014-05-11 22 views
2

我正在尝试使用Justin Toth的C#端口TouchImageView。图像正确显示(它甚至对Click事件起反应),但不会滚动或缩放。由于代码没有文档,我不确定如何使用它。是否自动缩放和滚动,是否必须手动设置或实现?下面是我的代码片段:在Xamarin中使用TouchImageView

Main.axml(该TouchImageView位于Customized.Layout命名空间)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android" 
    p1:orientation="vertical" 
    p1:minWidth="25px" 
    p1:minHeight="25px" 
    p1:layout_width="match_parent" 
    p1:layout_height="match_parent" 
    p1:id="@+id/alinearLayout2"> 
    <Button 
     p1:text="@string/butNextTurn" 
     p1:layout_width="match_parent" 
     p1:layout_height="wrap_content" 
     p1:id="@+id/abutton1" /> 
    <TextView 
     p1:text="Text" 
     p1:layout_width="match_parent" 
     p1:layout_height="wrap_content" 
     p1:id="@+id/acoordinates" 
     p1:layout_alignParentBottom="true" 
     p1:textColor="@color/brick" /> 
    <Customized.Layout.TouchImageView 
     p1:id="@+id/aview" 
     p1:layout_width="match_parent" 
     p1:layout_height="match_parent" /> 
</LinearLayout> 

MainActivity.cs:

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     SetContentView(Resource.Layout.Main); 

     Customized.Layout.TouchImageView view = FindViewById<Customized.Layout.TouchImageView>(Resource.Id.aview); 

     if (view != null) 
     { 
      view.SetImageResource(Resource.Drawable.image); 
      view.VerticalScrollBarEnabled = true; 
      view.HorizontalScrollBarEnabled = true; 
     } 
    } 

回答

4

一段时间后,fabionuno回答我的问题here

在TouchImageView.cs的代码中

SetOnTouchListener(new TouchImageViewListener(this)); 

应改为

base.SetOnTouchListener(new TouchImageViewListener(this)); 

无论如何,对于TouchImageView被证明是非常慢的(至少在我的情况)高画质图像。对于任何有类似问题的人,我建议使用实现GestureListener的WebView(或者你自己的继承WebView的类)(如Xamarin tutorial所述)

相关问题