handler.postdelayed не работает в MotionLayout

С тех пор конвертировать ConstraintLayout в MotionLayout handler.postdelayed не работает

это мои коды

Макет

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/jjjk"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    app:layoutDescription="@xml/chapter2_scene2">

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:src="@drawable/ic_launcher_background"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.3"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.5" />

</androidx.constraintlayout.motion.widget.MotionLayout>

Ява

Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {
            public void run() {
                imageView.setVisibility(View.VISIBLE);
            }
        }, 100);

Но это работает, если я пишу imageView.setVisibility(View.VISIBLE); вне handler.postdelayed

Проблема в том, что я android:visibility="gone" вид изображения

Если я использую android:visibility="invisible", проблем нет

Но я хочу отложить отображение больших изображений этим методом, чтобы страница загружалась хорошо

В чем проблема?


person alkkhu    schedule 03.11.2020    source источник


Ответы (1)


Это зависит, когда вы вызываете этот метод. Это должно работать, если вы вызываете его, когда вам видна активность/фрагмент. Попробуй это :

    @Override
    protected void onResume() {
        Handler mHandler = new Handler(Looper.myLooper());
        mHandler.postDelayed(new Runnable() {
            public void run() {
                View imageView = findViewById(R.id.image_view);
                imageView.setVisibility(View.VISIBLE);
            }
        }, 1000);
        super.onResume();
    }
person i30mb1    schedule 03.11.2020
comment
Этот метод не решил проблему. Обратите внимание, что я отредактировал свой вопрос. - person alkkhu; 03.11.2020