TextSwitcher使用示例
2013-01-10 16:48
302 查看
mainActivity如下:
main.xml如下:
package c.c; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AnimationUtils; import android.widget.TextSwitcher; import android.widget.TextView; import android.widget.ViewSwitcher.ViewFactory; public class MainActivity extends Activity { private TextSwitcher mIextSwitcher; private String texts []; private int textIndex=0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init(){ texts=new String[]{"空山新雨后","天气晚来秋","明月松间照","清泉石上流"}; mIextSwitcher=(TextSwitcher) findViewById(R.id.textSwitcher); //设置用于显示文字的TextView mIextSwitcher.setFactory(new ViewFactory() { public View makeView() { TextView textView=new TextView(MainActivity.this); textView.setTextSize(30); return textView; } }); //处理点击事件 mIextSwitcher.setOnClickListener(new ClickListenerImpl()); //设置文字进入和退出动画 mIextSwitcher.setInAnimation (AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left)); mIextSwitcher.setOutAnimation (AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left)); //设置初始时显示的文字 mIextSwitcher.setText(texts[textIndex]); } private class ClickListenerImpl implements OnClickListener { public void onClick(View v) { textIndex++; if (textIndex == texts.length) { textIndex = 0; } mIextSwitcher.setText(texts[textIndex]); } } }
main.xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextSwitcher android:id="@+id/textSwitcher" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> </RelativeLayout>
相关文章推荐
- TextSwitcher使用示例
- 安卓滚动字幕以及TextSwitcher、ImageSwitcher使用
- ImageSwitcher使用示例
- EditText使用示例
- ImageSwitcher使用示例
- TextSwitcher 使用详解
- 安卓控件TextSwitcher的使用(实现Textview的上下滚动)
- Android学习笔记 TextSwitcher文本切换组件的使用
- Android零基础入门第55节:ImageSwitcher和TextSwitcher使用
- jquery ready函数、css函数及text()使用示例
- Test_TextSwitcher 使用方法
- 控件使用TextSwitcher、Gallery 、ImageSwitcher、GridView、ListView、ExpandableList
- Material Design之TextInputLayout使用示例
- Material Design之TextInputLayout使用示例
- TextView中getCompoundDrawables()方法使用示例
- jquery ready函数、css函数及text()使用示例
- Android零基础入门第55节:ImageSwitcher和TextSwitcher使用
- Material Design之TextInputLayout使用示例
- TextView中getCompoundDrawables()方法使用示例
- 使用text方法获取Html元素文本信息示例