[Android]FloatingText仿点赞+1等效果

[Android]FloatingText仿点赞+1等效果

@Author GQ 20160729日  

自定义View,可以仿点赞往上飘+1的一个特效,或者点击加入
购物车商品抛物线特效。

FloatingText 是一个能够在任何控件之上执行漂浮效果动画的控件。

原文github地址

效果图

这里写图片描述

1. AndroidStudio使用

dependencies {

    compile 'com.ufreedom.uikit:FloatingTextLibrary:0.2.0'

}

2. 使用

FloatingText   floatingText = new FloatingText.FloatingTextBuilder(Activity)
    .textColor(Color.RED) // 漂浮字体的颜色
    .textSize(100)   // 浮字体的大小
    .textContent("+1000") // 浮字体的内容
    .offsetX(100) // FloatingText 相对其所贴附View的水平位移偏移量
    .offsetY(100) // FloatingText 相对其所贴附View的垂直位移偏移量
    .floatingAnimatorEffect(FloatingAnimator) // 漂浮动画
    .floatingPathEffect(FloatingPathEffect) // 漂浮的路径
    .build();

floatingText.attach2Window(); //将FloatingText贴附在Window上

//启动漂浮效果
floatingText.startFloating(View); // 传入一个View,FloatingText 就会相对于这个View执行漂浮效果
  • 自定义漂浮动画
    通过实现 FloatingAnimator 接口可以实现自定义漂浮动画,详情查看原github。

  • 自定义漂浮路径

    通过实现 FloatingPathEffect 和 FloatingPathAnimator 可以自定义路径动画

    FloatingPath 代表浮动路径

  • JAVA

// +1 向上移动效果
final View layoutTranslateFloating = findViewById(R.id.layoutTranslateView);
final View translateFloatingView = findViewById(R.id.translateView);
final FloatingText   translateFloatingText = new FloatingText.FloatingTextBuilder(MainActivity.this)
                .textColor(Color.RED)
                .textSize(100)
                .textContent("+1")
                .build();
        translateFloatingText.attach2Window();

        assert layoutTranslateFloating != null;
        layoutTranslateFloating.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                translateFloatingText.startFloating(translateFloatingView);
            }
        });


//+1 放大效果

View layoutScaleView = findViewById(R.id.layoutScaleView);
final View scaleView = findViewById(R.id.scaleView);
final FloatingText  scaleFloatingText = new FloatingText.FloatingTextBuilder(MainActivity.this)
                .textColor(Color.parseColor("#7ED321"))
                .textSize(100)
                .offsetY(-100)
                .floatingAnimatorEffect(new ScaleFloatingAnimator())
                .textContent("+1")
                .build();
        scaleFloatingText.attach2Window();

        assert scaleView != null;
        assert layoutScaleView != null;
        layoutScaleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                scaleFloatingText.startFloating(scaleView);
            }
        });


//自定义 螺旋上升动画
final FloatingText  cubicFloatingText = new FloatingText.FloatingTextBuilder(MainActivity.this)
                .textColor(Color.RED)
                .textSize(100)
                .floatingAnimatorEffect(new CurvePathFloatingAnimator())
                .floatingPathEffect(new CurveFloatingPathEffect())
                .textContent("Hello! ")
                .build();
        cubicFloatingText.attach2Window();


        View layoutCurveView = findViewById(R.id.layoutCurveView);
        final View curveView = findViewById(R.id.curveView);
        assert curveView != null;
        assert layoutCurveView != null;
        layoutCurveView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cubicFloatingText.startFloating(curveView);
            }
        });
  • XML
<FrameLayout
        android:id="@+id/layoutTranslateView"
        android:layout_width="234.4dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        >

        <TextView
            android:id="@+id/translateView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:text="Translate Floating"
            android:textColor="@android:color/white" />

    </FrameLayout>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现仿抖音双击点赞特效,可以使用Android中的GestureDetector类,它可以检测手势事件。具体实现步骤如下: 1.在布局文件中,创建一个ImageView控件,并设置图片资源。 2.在Java代码中,实例化GestureDetector类,并在onTouchEvent()方法中传入MotionEvent事件。 3.在GestureDetector的onDoubleTap()方法中,实现双击点赞的逻辑。 4.在GestureDetector的onSingleTapConfirmed()方法中,实现单击事件的逻辑。 下面是实现代码示例: ``` public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener { ImageView imageView; GestureDetector gestureDetector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = findViewById(R.id.imageView); gestureDetector = new GestureDetector(this, this); gestureDetector.setOnDoubleTapListener(this); } @Override public boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); return super.onTouchEvent(event); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { // 单击事件逻辑 return true; } @Override public boolean onDoubleTap(MotionEvent e) { // 双击事件逻辑 return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return true; } @Override public boolean onDown(MotionEvent e) { return true; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return true; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return true; } } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值