高德地图大头针Marker跳动效果

自定义控件MarkerView

 /**
  *版权:
  *@创建者:shuquan
  *创建时间:2020/10/23
  *模块:com.zsh.cdb.ui
  *描述:大头针跳动效果
  */

public class MarkerView extends View {

 


    public MarkerView (Context context) {
        this(context, null);
    }

    public MarkerView (Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MarkerView (Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 给大头针添加跳动动画。
     */
    ObjectAnimator mTAnimator1;
    ObjectAnimator mTAnimator2;

    @SuppressLint("NewApi")
    public ObjectAnimator transactionAnimWithMarker() {
        if (getVisibility() != View.VISIBLE)
            return null;
        if (mTAnimator1==null){
            mTAnimator1 = ObjectAnimator.ofFloat(this, "translationY", getTranslationY(), getTranslationY() - Utils.dip2px(getContext().getApplicationContext(), 20));
            mTAnimator2 = ObjectAnimator.ofFloat(this, "translationY", getTranslationY() - Utils.dip2px(getContext().getApplicationContext(), 20), getTranslationY());
            mTAnimator1.setInterpolator(new DecelerateInterpolator());
            mTAnimator1.setDuration(400);
            mTAnimator2.setInterpolator(new AccelerateInterpolator());
            mTAnimator2.setDuration(200);
            AnimatorSet mSet1 = new AnimatorSet();
            mSet1.play(mTAnimator1).before(mTAnimator2);
            mSet1.start();
        }else{
            if (!mTAnimator1.isRunning()&&!mTAnimator2.isRunning()) {
                mTAnimator1 = ObjectAnimator.ofFloat(this, "translationY", getTranslationY(), getTranslationY() - Utils.dip2px(getContext().getApplicationContext(), 20));
                mTAnimator2 = ObjectAnimator.ofFloat(this, "translationY", getTranslationY() - Utils.dip2px(getContext().getApplicationContext(), 20), getTranslationY());
                mTAnimator1.setInterpolator(new DecelerateInterpolator());
                mTAnimator1.setDuration(400);
                mTAnimator2.setInterpolator(new AccelerateInterpolator());
                mTAnimator2.setDuration(200);
                AnimatorSet mSet1 = new AnimatorSet();
                mSet1.play(mTAnimator1).before(mTAnimator2);
                mSet1.start();
            }
        }
        return mTAnimator2;
    }
}

布局文件

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <com.amap.api.maps.MapView
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="visible" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#00000000"
            android:gravity="center"
            android:orientation="vertical">

            <com.demo.MarkerView
                android:id="@+id/local_img"
                android:layout_width="28dp"
                android:layout_height="31dp"
                android:background="@drawable/local2" />

            <View
                android:layout_width="5dp"
                android:layout_height="10dp"
                android:background="#00000000" />
        </LinearLayout>

        <TextView
            android:id="@+id/tv_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#36000000"
            android:paddingLeft="@dimen/qb_px_5"
            android:text=""
            android:textColor="#ED5814"
            android:textSize="10sp"
            android:visibility="gone" />
    </RelativeLayout>

使用

   localImg.transactionAnimWithMarker();


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值