我正在使用支持设计库在我的应用程序中实现FAB,并按照this guide来添加滚动行为时消失或重新出现的行为。我已经将提供给C#的ScrollAwareFABBehavior类转换为C#,但是出现以下编译器错误。

error: name clash: onStartNestedScroll(CoordinatorLayout,View,View,View,int) in ScrollAwareFABBehavior and onStartNestedScroll(CoordinatorLayout,V,View,View,int) in Behavior have the same erasure, yet neither overrides the other
public boolean onStartNestedScroll (android.support.design.widget.CoordinatorLayout p0, android.view.View p1, android.view.View p2, android.view.View p3, int p4)
where V is a type-variable:
V extends View declared in class Behavior Project.Droid E:\VS Projects\Project\Project.Droid\obj\Debug\android\src\md5fa22044078b50743372e010f51d93dc4\ScrollAwareFABBehavior.java


这是转换后的类:

public class ScrollAwareFABBehavior : FloatingActionButton.Behavior
{
    public ScrollAwareFABBehavior(Context context, IAttributeSet attrs) {
    }

    public override bool OnStartNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View directTargetChild, View target, int nestedScrollAxes) {
        return nestedScrollAxes == ViewCompat.ScrollAxisVertical ||
            base.OnStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
    }

    public override void OnNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        base.OnNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);

        var fab = (FloatingActionButton)child;

        if (dyConsumed > 0 && fab.Visibility == ViewStates.Visible) {
            fab.Hide();
        } else if (dyConsumed < 0 && fab.Visibility != ViewStates.Visible) {
            fab.Show();
        }
    }

}


我不确定为什么会收到此错误,因为我只是重写了基类中的两个方法,这是我做错了还是Xamarin Android中的错误?
我创建了a gist,显示了在Visual Studio中双击错误时显示的Java代码,

最佳答案

通过使用父类CoordinatorLayout.Behavior而不是FloatingActionButton.Behavior,您应该能够克服此问题:

https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.Behavior.html

我已经继续并暂时就此问题提交了一个错误:

https://bugzilla.xamarin.com/show_bug.cgi?id=34777

关于c# - 当覆盖FloatingActionButton.Behavior中的方法时,Xamarin Android名称发生冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31674372/

10-10 04:19