Chat bubble animation

醉酒当歌 提交于 2020-06-26 14:39:13

问题


I want to achieve animation when I send my message it goes from bottom to top like flying a bird (though I have done it :P) but while flying, that chat bubble view's radius is also changing(This is the thing I am not able to achieve).

Please help me to achieve this kind of animation or give me some sort of hint.

Thank you

I have used below code to set radius and then translate that view using xml file but not able to change radius on the go.

GradientDrawable gd = new GradientDrawable();

            // Specify the shape of drawable
            gd.setShape(GradientDrawable.RECTANGLE);

            // Set the fill color of drawable
            gd.setColor(Color.TRANSPARENT); // make the background transparent

            // Create a 2 pixels width red colored border for drawable
            gd.setStroke(2, Color.RED); // border width and color

            // Make the border rounded
            gd.setCornerRadius(15.0f);

            ((RelativeLayout) findViewById(R.id.rlvView)).setBackground(gd);

             Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.item_animation_from_bottom);

            ((RelativeLayout) findViewById(R.id.rlvView)).startAnimation(animation);


回答1:


You need to use ObjectAnimator (derivative class of ValueAnimator) to achieve animate any value (visible/invisible) of a view. Code below animate cornerRadius for one time from 15.0f to 0. Please try, I hope it helps.

     // Make the border rounded
    gd.setCornerRadius(15.0f);
    ((RelativeLayout) findViewById(R.id.rlvView)).setBackground(gd);

    ObjectAnimator animator = ObjectAnimator.ofFloat(gd, "cornerRadius", 0);
    animator.setInterpolator(new LinearInterpolator());
    animator.setDuration(800);
    animator.start();


来源:https://stackoverflow.com/questions/52515628/chat-bubble-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!