简体   繁体   English

android-如何滑出cardview内的按钮?

[英]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.

相关问题 如何使CardView在Android中上下滑动动画? - How to make cardView slide up and down animation in android? 如何在Android CardView中放大和缩小布局 - How to Zoom in and out layout in Android CardView 如何在cardView android中添加listView? - How to add listView inside cardView android? 如何根据android里面的imageView调整cardView? - How to adjust cardView according to imageView inside in android? 如何在android中滑入和滑出视图 - How to slide a view in and out in android 内置ListView的Android CardView-CardView上的onTouchListener不起作用 - Android CardView with ListView inside - onTouchListener on CardView not working 单击按钮如何将活动滑入和滑出? - How to slide-in and slide-out the Activity on clicking of button.? 如果我有动态的RecyclerView / CardView,如何知道CardView中单击了哪个按钮? - How can I know which button is clicked inside my CardView if I have a dynamic RecyclerView/CardView? 如何在使用recyclerView填充的cardView中添加按钮的OnclickListener? - How to add OnclickListener for button inside a cardView populated using a recyclerView? 如何使用“幻灯片”(类似于Nubank)创建卡片视图? - How to create a cardview with “slide” (similar to Nubank)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM