android控件17 TextSwitcher
2011-12-18 21:26
363 查看
1)/res/layout/main.xml
2)com.sxt.TextSwitcherActivity.java
3)如图
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextSwitcher android:id="@+id/textswitcher" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button" /> </LinearLayout>
2)com.sxt.TextSwitcherActivity.java
package com.sxt; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.TextSwitcher; import android.widget.TextView; import android.widget.ViewSwitcher.ViewFactory; public class TextSwitcherActivity extends Activity { /** Called when the activity is first created. */ int position = 0; private String [] texts = {"曹操","刘备","孙权","郭嘉","诸葛亮","周瑜"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)this.findViewById(R.id.button); //final对象,引用不变。final基本类型,数据不变。 final TextSwitcher textSwitcher = (TextSwitcher)this.findViewById(R.id.textswitcher); //显示视图,设置工厂类的makeView方法。 textSwitcher.setFactory(new ViewFactory() { @Override public View makeView() { // TODO Auto-generated method stub TextView textView = new TextView(TextSwitcherActivity.this); textView.setTextSize(30); textView.setTextColor(Color.YELLOW); return textView; } }); textSwitcher.setText(texts[position]); //设置切入动画 textSwitcher.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_in_left)); //设置切出动画 textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_out_right)); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(position < texts.length-1) { position ++; } else { position = 0; } textSwitcher.setText(texts[position]); } }); } }
3)如图
相关文章推荐
- 上接系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView
- Android 中文 API (17) —— TextSwitcher
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- Android 中文 API (17) —— TextSwitcher
- <转>Android 中文 API (17) —— TextSwitcher
- Android高级控件(View)之四TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- Android UI基础——TextSwitcher&ImageSwitcher控件
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListVi
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery...
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- Android控件之ImageSwitcher_图片切换和TextSwitcher_文字切换
- Day3.2--Android简单UI控件之TextView的高级使用--SpannableString的使用
- Android中EditText控件的几种使用方法
- Android之EditText控件使用
- Android学习系列之控件 AutoCompleteTextView邮箱后缀自动补全
- Android jni反射生成TextView控件
- Android:控件AutoCompleteTextView 自动提示
- Android UI控件之ImageSwitcher(图片切换)
- Android之AutoCompleteTextView控件使用