xerez
xerez

Reputation: 89

Android - Why this TextView is moving its position after changing its visibility programmatically?

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>

Upvotes: 0

Views: 44

Answers (0)

Related Questions