cobolero
cobolero

Reputation: 442

Button overlapping views on top of it

I made a custom view with a progress bar. To add it in all my fragments i made a base fragment. In the method onActivityCreated i added the following code:

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)
}

And it works, but, when i make it visible, the buttons overlapped the progres bar in my LoadingView. So, when i show it i added brintToFront() method on a first test (that didnt work) and i saw i also had to use invalidate

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

As this wasnt working either i started looking for a solution here and i found that the solution could be adding translationZ or elevation properties. So i tried to, but none is working.

The XML file of my view is:

<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>

What am i doing wrong?

Upvotes: 1

Views: 163

Answers (1)

Vitalii Malyi
Vitalii Malyi

Reputation: 894

I've tried this and settings translationZ to 6f or more brings my view in front of buttons. It seems that it should be set programmatically.

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

Upvotes: 2

Related Questions