Odtworzyłem mój problem w bardzo prosty sposób. Mam 3 widok tekstowy. 2 z nich są w osobnym LinearLayout
, trzeci jest na tym samym poziomie co LinearLayout
. Przełączam widoczność test1
i test2
i chciałbym, aby zniknęły (co działa). Ponadto chcę, aby test3
wsunął się w swoje nowe miejsce (miejsce: test1
i test2
). Nie mogę tego zrobić. test3
po prostu przyciąga do nowego punktu.LayoutTransition: Animate Zobacz obok rozwijającego się widoku
Jak mogę to osiągnąć?
Mój kod:
<?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>
A w mojej działalności:
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 rzeczywiście mają inny TextView
obok test1
i test2
który powinien być widoczny przez cały czas, więc ja nie można po prostu ukryć samego siebie.
Animacja w widoku znikającym nie działa bez AnimationListener. W tym celu należy dołączyć AnimationListener i określić SetVisibility (View.GONE) w onAnimationEnd()! – gauravsapiens
Pracuję z tym kodem ... i to dla mnie w porządku .. –
Odkrywa widok, a następnie animuje. Z mojego doświadczenia wynikało to, że wyglądało to naprawdę szkicowo. – Michael