[英]android - How to slide out a button inside a cardview?
So far all the tutorials I've seen online are about animating RecyclerView
items on add/delete, but not the buttons/views inside the item itself. 到目前为止,我在网上看到的所有教程都是关于在添加/删除过程中对RecyclerView
项目进行动画处理,而不是对项目本身内部的按钮/视图进行动画处理。
The effect I'm going for is this: I click a button to download some content, and when it completes without errors, the button should slide out (or fade out or just move in any way) so that the user can't interact with it anymore. 我要达到的效果是:单击按钮下载一些内容,当它完成而没有错误时,该按钮应滑出(或淡出或以任何方式移动),以使用户无法进行交互有了它。
Sample card inside a RecyclerView: RecyclerView中的样本卡:
--------------------------
| Some content |
| |
| [Preview] [Download] | // <-- The Download button should go away,
-------------------------- // leaving the Preview button in the middle
I've tried android:animateLayoutChanges="true"
in the item layout xml but it had no effect after setting the download button's visibility to View.GONE
. 我已经在项目布局xml中尝试了android:animateLayoutChanges="true"
,但是将下载按钮的可见性设置为View.GONE
后,它没有任何作用。 In another attempt, I called viewHolder.button.animate().x(some_number)
in the adapter, but it did nothing as well. 在另一种尝试中,我在适配器中调用了viewHolder.button.animate().x(some_number)
,但它也没有执行任何操作。 Am I missing something? 我想念什么吗? Or is there no easy way of going about this simple animation? 还是没有简单的方法来制作这个简单的动画?
Please guide me. 请指导我。
You can use ObjectAnimator for translation of objects. 您可以使用ObjectAnimator转换对象。
http://developer.android.com/guide/topics/graphics/prop-animation.html http://developer.android.com/guide/topics/graphics/prop-animation.html
How to translate animation on an image diagonally? 如何对角转换图像上的动画?
Ex: 例如:
ObjectAnimator translation = ObjectAnimator.ofFloat(buttonView, "translationX", 0);
translation.setInterpolator(new DecelerateInterpolator());
translation.setDuration(300);
translation.start();
Change the value 0 to your wish. 将值0更改为所需的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.