【发布时间】:2020-07-28 01:18:34
【问题描述】:
当某些内容完成加载时,我实现了进度条可见性从可见变为不可见。当父视图是协调器布局时,它工作正常。现在我将它切换到约束布局,突然它不再工作了。
此更改是通过侦听点击的界面以编程方式完成的。当在片段内完成点击时,回调设置活动内的可见性关闭/打开。它工作得很好,但现在不行了。
代码基本上是这样的:在我的片段interface?.progressBarOff() 和我的活动中
override fun progressBarOff() {
progressbar.visibility = View.INVISIBLE // this line is getting called. so no problems with the interface
}
progressBarOn() 方法与此类似。
我试过了:
- runOnUiThread 什么都不做
- 可见性更改在我的活动中在
onCreate内起作用。但是,当从界面更改可见性时,它被调用但什么也不做。如果我在onCreate内将可见性设置为VISIBLE,它将保持可见但无法更改。 -
view.visibility = ConstraintLayout.VISIBLE效果不佳。 -
view.visibility = View.GONE效果不佳。
我在网上查找了为什么它不起作用的答案,有人说这是关于 Groups 但我还没有使用组。
MAIN_ACTIVITY.XML
<?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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blackBackground"
android:nestedScrollingEnabled="false"
app:layoutDescription="@xml/activity_main_scene"
app:motionDebug="SHOW_ALL">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/player_background"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000000"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/main_player"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@id/player_background"
app:layout_constraintTop_toTopOf="@id/player_background" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:theme="@style/TransparentActionBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/BlackActionBarPopUp" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintTop_toBottomOf="@id/player_background"
app:navGraph="@navigation/mobile_navigation" />
<ProgressBar // THIS PROGRESS BAR
android:id="@+id/main_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="@drawable/navbar_background"
app:itemIconTint="@drawable/navbar_colors"
app:itemTextColor="@drawable/navbar_colors"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.motion.widget.MotionLayout>
【问题讨论】:
-
确保您不要将
progressbarView 放在任何ConstraintLayout Group中,否则会破坏可见性 -
感谢您的建议,但除了接口之外,我的代码中没有使用进度条
-
发布您的 xml 布局
-
完成,请查看。谢谢
标签: android android-layout android-view android-constraintlayout