【问题标题】:android - How to slide out a button inside a cardview?android - 如何在卡片视图中滑出按钮?
【发布时间】:2015-10-23 17:25:34
【问题描述】:

到目前为止,我在网上看到的所有教程都是关于在添加/删除时为 RecyclerView 项目设置动画,而不是项目本身内部的按钮/视图。

我想要的效果是这样的:我点击一个按钮来下载一些内容,当它没有错误地完成时,按钮应该滑出(或淡出或以任何方式移动),以便用户可以不再与它互动。

RecyclerView 中的示例卡片:

--------------------------
|       Some content     |
|                        |
| [Preview]   [Download] |      // <-- The Download button should go away, 
--------------------------      //     leaving the Preview button in the middle

我在项目布局 xml 中尝试了android:animateLayoutChanges="true",但在将下载按钮的可见性设置为View.GONE 后它没有任何效果。在另一次尝试中,我在适配器中调用了viewHolder.button.animate().x(some_number),但它什么也没做。我错过了什么吗?还是没有简单的方法来制作这个简单的动画?

请指导我。

【问题讨论】:

    标签: android animation


    【解决方案1】:

    您可以使用 ObjectAnimator 来翻译对象。

    http://developer.android.com/guide/topics/graphics/prop-animation.html

    How to translate animation on an image diagonally?

    例如:

      ObjectAnimator translation = ObjectAnimator.ofFloat(buttonView, "translationX", 0);
    
      translation.setInterpolator(new DecelerateInterpolator());
      translation.setDuration(300);
      translation.start();
    

    将值 0 更改为您的愿望。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多