【问题标题】:Android CardView AlphaAndroid CardView Alpha
【发布时间】:2015-02-25 19:38:52
【问题描述】:

有什么办法可以在android中改变 CardView 的 alpha。无论我尝试什么都行不通。我尝试了这个,甚至尝试更改围绕它的框架布局的 alpha,但没有任何效果。

Footer.findViewById(R.id.base).setVisibility(View.VISIBLE);
                ViewPropertyAnimator.animate(Footer.findViewById(R.id.base)).cancel();
                ViewPropertyAnimator.animate(Footer.findViewById(R.id.base)).alpha(1f).setDuration(1000).setListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animator) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animator) {
                        Footer.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animator) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animator) {

                    }
                }).start();

【问题讨论】:

  • 您是否正在尝试删除一张卡片,同时它正在被删除,您正在逐渐淡出它?
  • K..我在下面添加了我的答案
  • 下面发布的代码对您有用吗?

标签: android alpha material-design android-cardview


【解决方案1】:

试试这个,

首先在anim文件夹中添加以下代码,代码分为两部分,一是从左向右移动卡片,二是在该过程中将卡片淡出。

move_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:toXDelta="100%"
        android:interpolator="@android:anim/linear_interpolator"/>
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
           android:interpolator="@android:anim/decelerate_interpolator"
           android:fromAlpha="1.0"
           android:duration="400"
           android:toAlpha="0.0"/>
</set>

在java代码中调用AnimationUtils.loadAnimation()如下

cardview.startAnimation(AnimationUtils.loadAnimation(context, R.anim.move_right));

这将导致卡片视图从左向右移动并逐渐淡出。

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 2020-11-15
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多