因此,我開發了一個代碼,當應用程序中的某個按鈕被按下時,它應該顯示在帶有一些動畫的Textview中(以增加一些樂趣)。是否有可能在文本視圖中有文字動畫,或者我應該使用Canvas還是SurfaceView來用動畫來繪製這個aplhabets?如何使用Android SDK製作文字動畫?
對於這方面的一些代碼示例,任何幫助都會很棒。
因此,我開發了一個代碼,當應用程序中的某個按鈕被按下時,它應該顯示在帶有一些動畫的Textview中(以增加一些樂趣)。是否有可能在文本視圖中有文字動畫,或者我應該使用Canvas還是SurfaceView來用動畫來繪製這個aplhabets?如何使用Android SDK製作文字動畫?
對於這方面的一些代碼示例,任何幫助都會很棒。
做喜歡的事,下面 「animation.xml」
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewFlipper android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:flipInterval="2000"
android:layout_marginBottom="20dip" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="@string/animation_2_text_1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="@string/animation_2_text_2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="@string/animation_2_text_3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:text="@string/animation_2_text_4"/>
</ViewFlipper>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="@string/animation_2_instructions"
/>
<Spinner android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
「主要業務」
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.animation);
mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper));
mFlipper.startFlipping();
Spinner s = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, mStrings);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
s.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView parent, View v, int position, long id) {
switch (position) {
case 0:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_up_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_up_out));
break;
case 1:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
break;
case 2:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
break;
default:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.hyperspace_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.hyperspace_out));
break;
}
}
public void onNothingSelected(AdapterView parent) {
}
private String[] mStrings = {
"Push up", "Push left", "Cross fade", "Hyperspace"};
private ViewFlipper mFlipper;
}
「的strings.xml」
<string name="animation_2_text_1">Freedom</string>
<string name="animation_2_text_2">is nothing else but</string>
<string name="animation_2_text_3">a chance to be better.</string>
<string name="animation_2_text_4">— Albert Camus</string>
<string name="animation_2_instructions">Select an animation:</string>
我會試試這個。感謝幫助。 – GamDroid 2010-11-15 05:33:22
不客氣。 – 2010-11-15 06:02:52
您期望什麼樣的動畫? SDK中提供了諸如轉置或旋轉之類的簡單動畫。 – xandy 2010-11-15 05:21:39
是換位會做。還有一些效果,如閃爍,褪色,字母隨機顏色變化等。 – GamDroid 2010-11-15 05:31:52