我有一个扩展 HorizontalScrollView 的类。但我不知道如何在 xml 中使用它。如果我使用我的类名作为 xml 标记,我得到一个错误:Error inflating class MyClass
我的代码:
public class ToothScroller : HorizontalScrollView
{
private GestureDetector mGestureDetector;
public ToothScroller(Context context) : base(context)
{
}
public ToothScroller(Context context, IAttributeSet attrs) : base(context, attrs)
{
SetFadingEdgeLength(0);
}
public ToothScroller(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
}
public ToothScroller(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public override bool OnInterceptTouchEvent (Android.Views.MotionEvent ev)
{
Console.WriteLine(this.ScrollX);
return base.OnInterceptTouchEvent (ev);
}
}
还有我的 xml (axml) 代码:
<MyClass
android:id="@+id/scrollMyClass"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/imageSomething"
android:fillViewport="true"
android:background="@drawable/pusherbg">
<RelativeLayout
android:id="@+id/layoutSomething"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</MyClass>
谢谢你的帮助。