Views_TextSwitcher

old/API_Demo 2010. 5. 6. 16:05

[TextSwitcher1.java]

public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
        View.OnClickListener {

    private TextSwitcher mSwitcher;

    private int mCounter = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.text_switcher_1);

        mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
        mSwitcher.setFactory(this);

        Animation in = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in);
        Animation out = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out);
        mSwitcher.setInAnimation(in);
        mSwitcher.setOutAnimation(out);

        Button nextButton = (Button) findViewById(R.id.next);
        nextButton.setOnClickListener(this);

        updateCounter();
    }

    public void onClick(View v) {
        mCounter++;
        updateCounter();
    }

    private void updateCounter() {
        mSwitcher.setText(String.valueOf(mCounter));
    }

    public View makeView() {
        TextView t = new TextView(this);
        t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        t.setTextSize(36);
        return t;
    }
}


[text_switcher_1.xml]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <Button android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text_switcher_1_next_text" />

    <TextSwitcher android:id="@+id/switcher"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
 

'old > API_Demo' 카테고리의 다른 글

Views_WebView  (0) 2010.05.06
Views_Visibility  (0) 2010.05.06
Views_Tabs_Content By Intent  (0) 2010.05.06
Views_Tabs_Content By Factory  (0) 2010.05.06
Views_Tabs_Content By Id  (0) 2010.05.06
Posted by jazzlife
,