아주 간단한 표현으로 문제를 재현했습니다. 3 TextViews 있습니다. 그 중 2 개는 별도 LinearLayout
이고, 세 번째는 LinearLayout
과 같은 레벨입니다. 가시성을 test1
및 test2
으로 바꿔보기로하고 있는데, 나는 그 효과가 사라지는 것을보고 싶습니다. 또한 test3
을 새 장소로 밀어 넣고 싶습니다 (test1
및 test2
발생). 나는이 일을 할 수 없다. test3
그냥 새로운 지점에 스냅.LayoutTransition : 확대보기 옆에보기 애니메이션
어떻게해야합니까?
내 코드 :
<?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>
그리고 내 활동에 :
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;
}
});
}
}
편집 : 난 사실이 또 다른 TextView
다음 test1
와 항상 볼 수 있어야합니다 test2
, 그래서 LinearLayout
자체를 숨길 수 없습니다.
AnimationListener가 없으면 사라지는보기의 애니메이션이 작동하지 않습니다. 이를 위해 AnimationListener를 첨부하고 onAnimationEnd()에서 SetVisibility (View.GONE)를 지정해야합니다! – gauravsapiens
보기를 숨김 해제 한 다음 애니메이션을 적용합니다. 내 경험에 의하면 그것은 정말 개략적으로 보였다. – Michael
예, 안드로이드가 프래그먼트 및 객체 애니메이터로 성장하면서 현재 다른 방식으로 할 수 있지만 당시에는이 작업을 완료했습니다. –