TextSwitcherProject
2014-07-17 23:50
232 查看
MyDemo.java
package com.jackie.textswitcherproject;import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;
public class MyDemo extends Activity {
private TextSwitcher myTextSwitcher = null;
private Button but = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
this.myTextSwitcher = (TextSwitcher) super
.findViewById(R.id.myTextSwitcher);
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));
this.but = (Button) super.findViewById(R.id.but);
this.but.setOnClickListener(new OnClickListenerImpl());
}
private class OnClickListenerImpl implements OnClickListener {
@Override
public void onClick(View arg0) {
MyDemo.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 text = new TextView(MyDemo.this);
text.setBackgroundColor(0xffffffff);
text.setTextColor(0xff000000);
text.setLayoutParams(new TextSwitcher.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
text.setTextSize(30);
return text;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_demo, menu);
return true;
}
}
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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MyDemo" >
<TextSwitcher
android:id="@+id/myTextSwitcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/but"
android:layout_below="@id/myTextSwitcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="切换时间"/>
</RelativeLayout>
相关文章推荐
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView
- 通知公告TextSwitcher自动上下滚动带点击事件
- 安卓滚动字幕以及TextSwitcher、ImageSwitcher使用
- TextSwitcher实现文本自动垂直滚动
- Android UI之ImageSwitcher && TextSwitcher 实现图文翻页
- Your First Text Mining Project with Python in 3 steps
- TextSwitcher上下滚动的实现和处理点击事件
- Android零基础入门第55节:ImageSwitcher和TextSwitcher使用
- TextSwitcher实现分析
- TextSwitcher实现文字轮播效果
- Android TextSwitcher实现文字上下翻牌效果(铜板街)
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- TextSwitcher,ImageSwitcher切换器
- ViewAnimator 之(一) ImageSwitcher和TextSwitcher
- TextSwitcher,译为文字转换器控件
- Android之TextSwitcher
- android 之 TextSwitcher 学习
- ImageSwitcherProject 图片浏览器
- Android高级控件(View)之四TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- TextSwitcher 跑马灯算法完善