Android学习笔记 TextSwitcher文本切换组件的使用
2013-10-08 11:22
369 查看
activity_main.xml
MainActivity.java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <TextSwitcher android:id="@+id/myTextSwitcher" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示当前时间" /> </LinearLayout>
MainActivity.java
public class MainActivity extends Activity { private Button btn=null; private TextSwitcher myTextSwitcher=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.btn=(Button)super.findViewById(R.id.btn); this.myTextSwitcher=(TextSwitcher)super.findViewById(R.id.myTextSwitcher); this.btn.setOnClickListener(new OnClickListenerImpl()); this.myTextSwitcher.setFactory(new ViewFactoryImpl()); this.myTextSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); this.myTextSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); } private class OnClickListenerImpl implements OnClickListener{ @Override public void onClick(View v) { MainActivity.this.myTextSwitcher.setText("当前时间为:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date())); } } private class ViewFactoryImpl implements ViewFactory{ @Override public View makeView() { TextView myTextView=new TextView(MainActivity.this); myTextView.setBackgroundColor(0xFFFFFFFF); myTextView.setTextColor(0xFF000000); myTextView.setLayoutParams(new TextSwitcher.LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT )); return myTextView; } }
相关文章推荐
- Android学习笔记 ImageSwitcher图片切换组件的使用
- Android中的AutoCompleteTextView(随笔提示文本)组件的简单使用
- Android学习笔记:使用ViewPager组件实现图片切换
- Android开发之文本切换组件TextSwi…
- 使用Swing组件编写一个支持中文文本编辑程序ChineseTextEdit.java
- Android学习笔记26-图片切换控件ImageSwitcher的使用
- 控件:文本切换 --- TextSwitcher
- TextSwitcher类(TextView改变文本动画切换)
- Android学习笔记26:图片切换控件ImageSwitcher的使用
- Android开发之ImageSwitcher组件的使用以及设置图片切换的效果
- Android中的AutoCompleteTextView(随笔提示文本)组件的简单使用
- Android学习之路---ImageSwitcher和TextSwitcher切换图片及文本
- UGUI Text组件实际文本宽高的获取
- Android中使用react-native框架中的View组件如何使其中的文本换行
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
- Android自定义控件2:自定义带下划线的文本或按钮、组合使用可切换tab
- jquery之设置元素内容(替换HTML或文本内容,使用html()和text()方法)
- Android EditText/TextView使用SpannableString显示复合文本
- 在flex4 中使用 s:RichEditableText来显示html文本
- TextSwitcher--文本切换器