I've recreated my problem to a very simple representation. I have 3 TextViews. 2 of them are in a seperate LinearLayout, the third is on the same level as the LinearLayout.
I'm toggling the visibility of test1 and test2, and I'd like to see them fade away (which works). Furthermore, I want test3 to slide into his new place (taking place of test1 and test2). I can't make this happen. test3 just snaps to it's new point.
How can I achive this?
My code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click" />
<LinearLayout android:animateLayoutChanges="true"
android:id="@+id/child1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/test1"
android:layout_width="match_parent" android:visibility="gone"
android:layout_height="wrap_content"
android:text="TEST1" />
<TextView
android:id="@+id/test2"
android:layout_width="match_parent" android:visibility="gone"
android:layout_height="wrap_content"
android:text="TEST2" />
</LinearLayout>
<TextView
android:id="@+id/test3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST3" />
</LinearLayout>
And in my Activity:
public class LayoutAnimations extends Activity {
private boolean toggle = true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_animations);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (toggle) {
findViewById(R.id.test1).setVisibility(View.VISIBLE);
findViewById(R.id.test2).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.test1).setVisibility(View.GONE);
findViewById(R.id.test2).setVisibility(View.GONE);
}
toggle = !toggle;
}
});
}
}
Edit: I actually have another TextView next to test1 and test2 which should be visible at all times, so I can't just hide the LinearLayout itself.