Luca Pellizzari
Luca Pellizzari

Reputation: 374

Setting the View visibility to View.GONE, makes it invisible, still takes up space

I have a view that I want to collapse, so I set the visibility to View.GONE the view becomes invisible, but it still takes up space.

I don't know what it might be, someone has ideas?

Here is an image before (View D): Here is an image before

Here is an image after (View D): enter image description here

Here is the layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
android:background="@color/mainColor"
android:clipToPadding="false"
android:fillViewport="false"
android:scrollbars="none">

<android.support.constraint.ConstraintLayout
    android:id="@+id/options_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true">

    <!-- other irrelevants views -->

    <TextView
        android:id="@+id/time_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:fontFamily="sans-serif"
        android:text="@string/toolbar_options_title_time"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/option_hexa_sorting" />

    <com.development.mekanius.bounce.customElements.HexaRadioGroupView
        android:id="@+id/option_hexa_time"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/time_title" />

    <Button
        android:id="@+id/option_create_post"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="32dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/option_hexa_time" />

</android.support.constraint.ConstraintLayout>

Thanks in advance

Upvotes: 1

Views: 2202

Answers (2)

Abhas Arya
Abhas Arya

Reputation: 470

I spent hours debugging why this was happening to me and stumbled upon your answer. I was mutating visibility from an Rx-Java thread that was supposed to be operating on the main thread but apparently not! Doing a view.post {..} solved the issue for me! Thanks so much

Upvotes: 0

Luca Pellizzari
Luca Pellizzari

Reputation: 374

First of all, sorry for the late reply, but I have been stuck on finals and I didn't have much time.

Ok, the problem was a whole other story.
I'm using Spotify's Mobius as a state machine:
https://github.com/spotify/mobius

It's using a background thread to consume effects, and so acting on the UI gives an error. But for some reason the error was suppressed (was not on the logs and did't throw an exception), so I was seeing simply the view not obeying commands.

I came to this conclusion removing code lines until something worked.
Very old fashion.

Thanks for all that tried to help.

Upvotes: 2

Related Questions