简体   繁体   English

Android.Util.Property Class 在 C# 中的实现

[英]Android.Util.Property Class Implemention in C#

I have been banging my head for days to find some help but maybe I am not looking at the right place.几天来我一直在努力寻找帮助,但也许我没有找对地方。

I am following this article to replicate Twitter like button animation (I don't want to use rebuilt libraries) - http://frogermcs.github.io/twitters-like-animation-in-android-alternative/ I am following this article to replicate Twitter like button animation (I don't want to use rebuilt libraries) - http://frogermcs.github.io/twitters-like-animation-in-android-alternative/

I have a Custom View called LikeButtonView我有一个名为LikeButtonView的自定义视图

 public class LikeButtonView : FrameLayout, View.IOnClickListener
    {
        private static DecelerateInterpolator DECCELERATE_INTERPOLATOR = new DecelerateInterpolator();
        private static AccelerateDecelerateInterpolator ACCELERATE_DECELERATE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
        private static OvershootInterpolator OVERSHOOT_INTERPOLATOR = new OvershootInterpolator(4);
        private ImageView ivStar;
        private DotsView vDotsView;
       
        private AnimatorSet animatorSet;

        public LikeButtonView(Context context, IAttributeSet attrs) :
            base(context, attrs)
        {
            Initialize();
        }

        public LikeButtonView(Context context, IAttributeSet attrs, int defStyle) :
            base(context, attrs, defStyle)
        {
            Initialize();
        }

        public void OnClick(View v)
        {
            vDotsView.setCurrentProgress(0);         
            animatorSet = new AnimatorSet();
            ObjectAnimator starScaleYAnimator = ObjectAnimator.OfFloat(ivStar, ImageView.ScaleYs, 0.2f, 1f);
            starScaleYAnimator.SetDuration(350);
            starScaleYAnimator.StartDelay = (250);
            starScaleYAnimator.SetInterpolator(OVERSHOOT_INTERPOLATOR);

            ObjectAnimator starScaleXAnimator = ObjectAnimator.OfFloat(ivStar, ImageView.ScaleXs, 0.2f, 1f);
            starScaleXAnimator.SetDuration(350);
            starScaleXAnimator.StartDelay = (250);
            starScaleXAnimator.SetInterpolator(OVERSHOOT_INTERPOLATOR);

            ObjectAnimator dotsAnimator = ObjectAnimator.OfFloat(vDotsView, DotsView.DOTS_PROGRESS, 0.2f, 1f);
            dotsAnimator.SetDuration(900);
            dotsAnimator.StartDelay = (50);
            dotsAnimator.SetInterpolator(ACCELERATE_DECELERATE_INTERPOLATOR);

            animatorSet.PlayTogether(
                   starScaleYAnimator,
                   starScaleXAnimator,
                   dotsAnimator
           );
            animatorSet.Start();         
        }

        private void Initialize()
        {
            var INF = LayoutInflater.From(Context).Inflate(Resource.Layout.view_like_button, this, true);
            ivStar = INF.FindViewById<ImageView>(Resource.Id.ivStar);
            vDotsView = INF.FindViewById<DotsView>(Resource.Id.vDotsView);           
            SetOnClickListener(this);
        }
    }

I am also using private DotsView vDotsView which is another custom view, which is a C# Replica of this view https://github.com/frogermcs/LikeAnimation/blob/master/app/src/main/java/frogermcs/io/likeanimation/DotsView.java我也在使用private DotsView vDotsView这是另一个自定义视图,它是这个视图https的 C# 副本/DotsView.java

In the above link, right at the end, I see the following在上面的链接中,在最后,我看到以下内容

  public static final Property<DotsView, Float> DOTS_PROGRESS = new Property<DotsView, Float>(Float.class, "dotsProgress") {
        @Override
        public Float get(DotsView object) {
            return object.getCurrentProgress();
        }

        @Override
        public void set(DotsView object, Float value) {
            object.setCurrentProgress(value);
        }
    };

It is Android.Util.Property getting used to get and set the progress用于getset进度的是 Android.Util.Property

ObjectAnimator dotsAnimator = ObjectAnimator.OfFloat(vDotsView, DotsView.DOTS_PROGRESS, 0.2f, 1f);

I am lost right here, I do not know how to implement this in C#?我在这里迷路了,我不知道如何在 C# 中实现这个? I have been trying different things but no luck with implementing public static final Property<DotsView, Float> DOTS_PROGRESS with exact parameters.我一直在尝试不同的事情,但没有用确切的参数实现public static final Property<DotsView, Float> DOTS_PROGRESS

If anyone can help would be highly appreciated.如果有人可以提供帮助,将不胜感激。

If this helps anyone, we can do something like the following如果这对任何人都有帮助,我们可以执行以下操作

[Register("DOTS_PROGRESS")]
public static Property DotsProgress {
   get {
         JniObjectReference objectValue = _members.get_StaticFields().GetObjectValue("DOTS_PROGRESS.Landroid/util/Property;");
                return Object.GetObject<Property>(objectValue.get_Handle(), 1);
       }
}

Found this package which was converted from java to C# https://www.fuget.org/packages/Karamunting.Android.HanksZyh.SmallBang/1.2.2/lib/monoandroid81/SmallBang.dll/Hanks.Library.Bang/DotsView?code=true Found this package which was converted from java to C# https://www.fuget.org/packages/Karamunting.Android.HanksZyh.SmallBang/1.2.2/lib/monoandroid81/SmallBang.dll/Hanks.Library.Bang/DotsView?代码=真

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM