gpt4 book ai didi

android - 按钮在它上面重叠 View

转载 作者:行者123 更新时间:2023-11-29 22:45:04 25 4
gpt4 key购买 nike

我制作了一个带有进度条的自定义 View 。为了将它添加到我所有的 fragment 中,我制作了一个基本 fragment 。在方法 onActivityCreated 中,我添加了以下代码:

activity?.run {
loading = LoadingView(this)
loading?.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
loading?.visibility = View.GONE
(view as? ViewGroup)?.addView(loading)
}

它有效,但是,当我使其可见时,按钮与我的 LoadingView 中的进度条重叠。所以,当我展示它时,我在第一次测试中添加了 brintToFront() 方法(没有用),我发现我还必须使用 invalidate

protected fun showLoading() {
loading?.visibility = View.VISIBLE
loading?.bringToFront()
loading?.invalidate()
}

因为这不起作用,我开始在这里寻找解决方案,我发现解决方案可以添加 translationZelevation 属性。所以我尝试了,但没有一个起作用。

我的 View 的XML文件是:

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

我做错了什么?

最佳答案

我试过这个并将 translationZ 设置为 6f 或更多,使我的 View 位于按钮前面。看来应该以编程方式设置。

protected fun showLoading() {
loading?.translationZ = 6f
loading?.visibility = View.VISIBLE
}

关于android - 按钮在它上面重叠 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58603224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com