मैं एक कार के विभिन्न कदमों के साथ एक एनीमेशन चाहता हूं जो चाल (अनुवाद) और घूर्णन जैसे "सीधे चालू करें, बाएं मुड़ें, सीधे चालू करें ...."।प्रोग्रामेटिक रूप से RotateAnimations कैसे करें के पूर्ण उदाहरण?
मैं इसे AnimationSet
में करने में सक्षम हूं, लेकिन "RELATIVE_TO_SELF" सेटिंग के साथ मेरी कार छवि के केंद्र के चारों ओर घूमने में विफल रहता हूं। मुझे इस उद्देश्य के लिए
Animation a = new RotateAnimation(0,90,Animation.RELATIVE_TO_SELF,0.5f,...)
पता है। फिर भी घूर्णन स्क्रीन के ऊपरी बाएं कोने (या कैनवास?) के आसपास होता है।
वर्तमान में मैं प्रत्येक एनीमेशन चरण के बाद स्थिति का ट्रैक रखने के द्वारा इसे हल कर रहा हूं, लेकिन यह उप-स्थानिक है।
मुझे लगता है कि मेरी प्रारंभिक लेआउट सेटअप फर्जी है:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<!-- view that draws some background -->
<de.bsd.turtlecar.SampleView android:id="@+id/graph_view"
android:layout_height="350px"
android:layout_width="fill_parent"
android:visibility="invisible"
/>
<!-- the car -->
<ImageView android:id="@+id/car_view"
android:src="@drawable/turtle_car"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="invisible"/>
</FrameLayout>
<Button ... onClick="run" ... />
</LinearLayout>
यह ऊपरी बाएँ कोने में कार (चलता एक अलग जगह में दिखाई देना चाहिए - जहां एनीमेशन बाद में शुरू होता है मूल रूप से और यह करना चाहिए। बाद में चले जाओ)।
मेरी कोड में रन बटन मैं कर के माध्यम से शुरू हो रहा है:
ImageView carView = (ImageView) findViewById(R.id.car_view);
print(carView);
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation a = new TranslateAnimation(
Animation.ABSOLUTE,200, Animation.ABSOLUTE,200,
Animation.ABSOLUTE,200, Animation.ABSOLUTE,200);
a.setDuration(1000);
animationSet.addAnimation(a);
RotateAnimation r = new RotateAnimation(0f, -90f,200,200); // HERE
r.setStartOffset(1000);
r.setDuration(1000);
animationSet.addAnimation(r);
...
तो यहाँ के साथ बिंदु पर, रोटेशन से काम करता है, लेकिन मैं ट्रैक रखने के लिए किया है। अगर मैं RELATIVE_TO_SELF घुमाता हूं, तो घूर्णन स्क्रीन के आसपास (0,0) होता है।
अतिरिक्त प्रश्न: एनीमेशन समाप्त होने के बाद कार को स्क्रीन पर रखने के लिए मैं क्या कर सकता हूं?
या क्या मैं पूरी तरह से गलत ट्रैक पर हूं?
नोट – Nilzor