Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Calling GONE and then VISIBLE makes the view to be shown in the wrong place
    primarykey
    data
    text
    <p>I have two views, A and B, and the view A is above the view B (both are linear layouts).</p> <p>When I, programmatically, set the view A to be GONE, it disappears and the view that was right below it (B) goes to the place of the view A (as expected). </p> <p>However, when I set the very same view (A) to VISIBLE again, it is being shown OVER the view B. I don't want that. I want the view B to go back to its original position (below the view A) which is what I thought it would happen (but it doesn't). How can I do that?</p> <p>Thank you in advance!</p> <h2>EDIT - Code</h2> <pre><code>package com.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.ScaleAnimation; import android.view.animation.Transformation; import android.widget.LinearLayout.LayoutParams; public class ViewGoneEffectActivity extends Activity implements OnClickListener { private View viewComEfeito = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewById(R.id.outroLinear).setOnClickListener(this); findViewById(R.id.segundo).setOnClickListener(this); viewComEfeito = findViewById(R.id.outroLinear); } @Override public void onClick(View view) { if (view.getId() == R.id.outroLinear) { view.startAnimation(new MyScaler(1.0f, 1.0f, 1.0f, 0.0f, 500, view, true)); }else if(view.getId() == R.id.segundo){ viewComEfeito.setVisibility(View.VISIBLE); } } public class MyScaler extends ScaleAnimation { private LayoutParams mLayoutParams; private int mMarginBottomFromY, mMarginBottomToY; private boolean mVanishAfter = false; public MyScaler(float fromX, float toX, float fromY, float toY, int duration, View view, boolean vanishAfter) { super(fromX, toX, fromY, toY); setDuration(duration); mVanishAfter = vanishAfter; mLayoutParams = (LayoutParams) view.getLayoutParams(); //int height = mView.getHeight(); int height = viewComEfeito.getHeight(); mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height; mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) - height; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); if (interpolatedTime &lt; 1.0f) { int newMarginBottom = mMarginBottomFromY + (int) ((mMarginBottomToY - mMarginBottomFromY) * interpolatedTime); mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin, mLayoutParams.rightMargin, newMarginBottom); viewComEfeito.getParent().requestLayout(); } else if (mVanishAfter) { viewComEfeito.setVisibility(View.GONE); } } } </code></pre> <p>}</p> <p>And here goes the XML:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:id="@+id/outroLinear" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Welcome to the real world" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="No" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Wow! =P" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Free your mind!" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="In Tylor we trust" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="First rule of fight club is" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:id="@+id/segundo" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload