使用运动版式开始与UI交互后,重置进度栏可见性 [英] Progress Bar Visibility reset after I start interacting with UI when using motion layout

查看:69
本文介绍了使用运动版式开始与UI交互后,重置进度栏可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ConstraintLayout版本:2.0.0-alpha3

ConstraintLayout version: 2.0.0-alpha3

所以我正在使用MotionLayout,我想创建类似的东西。 https://blog.stylingandroid.com/motionlayout-collapsing-toolbar-part -2 /

So I am using MotionLayout I wanted to create something similar to this. https://blog.stylingandroid.com/motionlayout-collapsing-toolbar-part-2/

我想要实现当用户输入活动时,当我输入 ProgressBar 时,加载数据(需要一些时间),我想隐藏 ProgressBar

I want to achieve When the user enters activity there is ProgressBar spinning when I load data (takes some time) I want ProgressBar to hide.

我的问题是,当我开始与UI ProgressBar 状态被重置并再次可见

My problem is that when I start interacting with UI ProgressBar state is reset and is visible again

我该怎么做才能防止progressBar在用户之后开始显示开始与之互动?

What should I do to prevent progressBar to start showing after the user starts interacting with it?

这里是简化版本

布局文件

layout file

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/collapsing_toolbar"
    tools:context=".MainActivity"
    tools:showPaths="true">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/scroll_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar_image">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <View
                android:layout_width="match_parent"
                android:layout_height="2000dp"
                android:background="#ff2"/>
        </FrameLayout>
    </androidx.core.widget.NestedScrollView>

    <ImageView
        android:id="@+id/toolbar_image"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@color/colorPrimary"
        android:src="@color/colorAccent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <TextView
        android:id="@+id/error"
        android:text="ERROR"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

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

此处是布局说明( xml / collapsing_toolbar

Here is layout description (xml/collapsing_toolbar)

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Transition
        app:constraintSetEnd="@id/collapsed"
        app:constraintSetStart="@id/expanded">

        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorId="@id/scroll_view"
            app:touchAnchorSide="top"/>
    </Transition>

    <ConstraintSet android:id="@+id/expanded">
        <Constraint
            android:id="@id/toolbar_image"
            android:layout_height="200dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/collapsed">
        <Constraint
            android:id="@id/toolbar_image"
            android:layout_height="?attr/actionBarSize"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
        </Constraint>

    </ConstraintSet>

</MotionScene>

这是一个简单的活动,我在1秒后隐藏了ProgressBar

and this is a simple activity where I hide ProgressBar after 1second

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Handler().postDelayed({
            progress_bar.visibility = View.GONE
            error.text="NEW ERROR"
            error.visibility = View.GONE
        }, 1000)
    }
}

我正在使用 androidx.constraintlayout:constraintlayout:2.0.0-alpha3

编辑:我也将其报告为错误 https://issuetracker.google.com / issues / 124812189

I also reported this as bug https://issuetracker.google.com/issues/124812189

编辑:的部分解决方案是将progress_bar和错误可见性设置为GO NE<<但是,这里也适用相同的情况,因此,如果您与加载进行交互,则可以看到 scrollView ,但是总比在有内容时看到ProgressBar更好。

partial solution for this is to set progress_bar and error visibility to GONE << However the same scenario applies here so if you interact with loading you can see scrollView, but it's better than to see ProgressBar when there should be content.

推荐答案

该错误现已修复!走上快乐生活,没有任何可见的毛刺:)

The bug is now fixed! Go and live your merry life without any visibility glitches :)

供将来的读者使用:这是MotionLayout中的已知错误,当​​用户触摸某些东西时状态会重置。 Nicolas在这里谈论这个话题: https://youtu.be/r8cYDlBOPaA?t=2276

For future readers: This was known bug in MotionLayout where the state reset when the user touched something. Nicolas is talking about this around here: https://youtu.be/r8cYDlBOPaA?t=2276

团队在Alpha 4中修复了该问题。

The team fixed it in Alpha 4.

这篇关于使用运动版式开始与UI交互后,重置进度栏可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆