android 동적 설정 Activity 전환 방향

2835 단어 자바androidxml
동적 설정 Activity 왼쪽 에서 오른쪽 에서 왼쪽으로
1. LayoutAnimation XML 작성
layout_left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/animation_left"
        android:delay="100%"
        android:animation="@anim/side_left" />


side_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
	<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>


layout_right_in.xml

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="100%"
        android:animation="@anim/side_right" />

side_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="-100%p" android:toXDelta="0"
            android:duration="@android:integer/config_shortAnimTime" />
</set>

2. Activity 에서 Layout Animation Controller 를 통 해 Layout 의 Layout Animation 을 동적 으로 설정 합 니 다.

LayoutAnimationController controller = null;
	Bundle extras;

	public void onCreate(Bundle saveInstanceState) {
		super.onCreate(saveInstanceState);
		// setContentView(R.layout.sales_memo_list);

		LayoutInflater factory = LayoutInflater
				.from(SalesMemoListActivity.this);
		final LinearLayout dialogEntryView = (LinearLayout) factory.inflate(
				R.layout.sales_memo_list, null);
		extras = getIntent().getExtras();
		if (extras != null) {
			String animation = extras.getString("animation");
			if (animation.equals("left")) {
				controller = AnimationUtils.loadLayoutAnimation(this,
						R.anim.layout_left_in);
			} else {
				controller = AnimationUtils.loadLayoutAnimation(this,
						R.anim.layout_right_in);
			}
			dialogEntryView.setLayoutAnimation(controller);
		}
		setContentView(dialogEntryView);
}

좋은 웹페이지 즐겨찾기