0

Initially both TextViews are visible and aligned correctly:

Both TextViews are visible.

After clicking the Button, I set both TextViews visibility to GONE. Second time I click on the Button, I set the visibility again to VISIBLE, but the result is the below:

Result after changing the visibility to GONE and back to VISIBLE.

Next times changing the visibility, I always get the same result.

How can I solve this to get always the appearance of the first image?

Thank you!

Layout:

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/iconos_futbolista"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:gravity="center_horizontal"
        android:orientation="horizontal"
        android:visibility="visible">

        <TextView
            android:id="@+id/posicion_tv"
            style="@style/IconosPerfilTextView"
            android:layout_marginEnd="8dp"
            android:backgroundTint="@color/green"
            android:text="@string/pos_medio" />

        <TextView
            android:id="@+id/seleccion_sub_fut_tv"
            style="@style/IconosPerfilTextView"
            android:alpha="0.15"
            android:padding="0dp"
            android:backgroundTint="@color/claret"
            android:text="@string/internacional_sub" />

    </LinearLayout>

    <Button
        android:id="@+id/boton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Cambiar"/>
    
</LinearLayout>

Style:

<style name="IconosPerfilTextView" >
    <item name="android:layout_width">64dp</item>
    <item name="android:layout_height">64dp</item>
    <item name="android:autoSizeTextType">uniform</item>
    <item name="android:background">@drawable/perfil_iconos_background</item>
    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textStyle">bold</item>
    <item name="android:gravity">center</item>
    <item name="android:padding">4dp</item>
</style>
2
  • I can't really explain why it lays out that way at the start, but it's apparently aligning the TextViews' baselines after you re-show it, which is LinearLayout's default behavior. Add android:baselineAligned="false" to the opening iconos_futbolista <LinearLayout> tag.
    – Mike M.
    Commented Apr 30, 2023 at 17:48
  • 1
    Hi @mike-m, your solution, worked even if you don't know why this is happening. Thank you so much!
    – xerez
    Commented May 1, 2023 at 11:09

0