سؤال

أنا وضعت الرسوم المتحركة في تخطيط مثل هذا:

<ViewSwitcher
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:inAnimation="@android:anim/slide_in_left"
    android:outAnimation="@android:anim/slide_out_right" >

كيف يمكنني أن أفعل نفس برمجيا?

هل كانت مفيدة؟

المحلول

يرجى قراءة الوثائق الخاصة بـ ViewSwitcher الطبقة ، فقد طريقتين لوضع داخل / خارج الرسوم المتحركة:

// load the two animations  
Animation animIn = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
Animation animOut = AnimationUtils.loadAnimation(context, android.R.anim.slide_out_right);
// set them on the ViewSwitcher
vs.setInAnimation(animIn);
vs.setOutAnimation(animOut);

نصائح أخرى

giveacodicetagpre.

يمكنك تخطي خطوة تحميل الرسوم المتحركة باستخدام AnimationUtils وبدلا من ذلك تمرير الموارد أنيم مباشرة:

switcher.setInAnimation(this, android.R.anim.slide_in_left);
switcher.setOutAnimation(this, android.R.anim.slide_out_right);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top