如何使用Android SDK做文字动画?如何使用、文字、动画、SDK

由网友(爱止步于欺骗)分享简介:所以,我已经开发,其中当从应用中的一些按钮为pressed应该得到显示在与一些动画TextView的(添加一些有趣)一个code。是否有可能有文字动画在TextView的或者我应该用帆布或SurfaceView绘制此aplhabets动画? So i have a code developed where when...

所以,我已经开发,其中当从应用中的一些按钮为pressed应该得到显示在与一些动画TextView的(添加一些有趣)一个code。是否有可能有文字动画在TextView的或者我应该用帆布或SurfaceView绘制此aplhabets动画?

So i have a code developed where when some button from the app is pressed it should get displayed in the Textview with some Animation(to add some fun). Is it possible to have text animations in Textview or should i use Canvas or SurfaceView for drawing this aplhabets with animation?

在这方面与一些code样品任何帮助将是巨大的。

Any help in this regard with some code sample will be great.

推荐答案

做类似如下animation.xml

Do something like below "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

"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>
阅读全文

相关推荐

最新文章