【问题标题】:How to hide the src in an imagebutton as you display loading animation如何在显示加载动画时隐藏图像按钮中的 src
【发布时间】:2021-04-21 02:40:48
【问题描述】:

当我播放加载动画时,如何在我的imageButton 中临时删除这个src,我目前正在做的是明确说visibility = gone 哪个offcourse 正在使我的按钮偏离比例,只显示加载微调器.这是我的xml。我也尝试将背景设置为 null,但是这种删除了 member_background 可绘制对象。

 <ImageButton
     android:id="@+id/memberButton"
     android:layout_width="48dp"
     android:layout_height="48dp"
     android:layout_alignParentTop="true"
     android:layout_marginStart="59dp"
     android:layout_marginTop="12dp"
     android:layout_marginEnd="30dp"
     android:layout_marginBottom="12dp"
     android:background="@drawable/member_background"
     android:src="@drawable/ic_member_icon"
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintEnd_toEndOf="parent"
     app:layout_constraintHorizontal_bias="1.0"
     app:layout_constraintStart_toEndOf="@+id/textView"
     app:layout_constraintTop_toBottomOf="@+id/view_one"
     app:layout_constraintVertical_bias="1.0" />


 <com.airbnb.lottie.LottieAnimationView
     android:id="@+id/animation_view"
     android:layout_width="30dp"
     android:layout_height="30dp"
     android:elevation="3dp"
     android:scaleType="centerInside"
     app:layout_constraintBottom_toBottomOf="@+id/memberButton"
     app:layout_constraintEnd_toEndOf="@+id/memberButton"
     app:layout_constraintStart_toStartOf="@+id/memberButton"
     app:layout_constraintTop_toTopOf="@+id/memberButton"
     app:lottie_autoPlay="true"
     app:lottie_loop="true"
     app:lottie_rawRes="@raw/white_spinner" />

【问题讨论】:

  • 我想到的一件事是,有另一个 ImageView 作为 ImageButton 的图标。现在,您可以通过设置图像或使布局可见或消失,轻松地将其替换为所有图像甚至布局。

标签: android xml kotlin


【解决方案1】:

试试这个

ImageButton image = findViewById(R.id.memberButton);
image.setVisibility(View.GONE);


    LottieAnimationView animationView
            = findViewById(R.id.animation_view);
    animationView
            .addAnimatorUpdateListener(
                    (animation) -> {
                        // Do something.
                    });
    animationView
            .playAnimation();
    if (animationView.isAnimating()) {
        // Do something.
    }


   new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            animationView.pauseAnimation();
            animationView.setVisibility(View.GONE);
            image.setVisibility(View.VISIBLE);
        }
    }, 3000);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    相关资源
    最近更新 更多