`
Aina_hk55HK
  • 浏览: 388579 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

Android TextSwitcher的使用

阅读更多
<?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">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="TextSwitcher" />
	<Button android:text="ok" android:id="@+id/Button01"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content">
	</Button>
	<TextSwitcher android:id="@+id/TextSwitcher01"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content">
	</TextSwitcher>
	<TextView android:text="@+id/TextView01"
		android:id="@+id/TextView01" android:layout_width="wrap_content"
		android:layout_height="wrap_content">
	</TextView>
</LinearLayout>



package com.Aina.Android;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

public class Test_TextSwitcher extends Activity implements ViewSwitcher.ViewFactory{
    /** Called when the activity is first created. */
	TextSwitcher ts;
	TextView tv2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn = (Button) this.findViewById(R.id.Button01);
        ts = (TextSwitcher) this.findViewById(R.id.TextSwitcher01);
        tv2 = (TextView) this.findViewById(R.id.TextView01);
        tv2.setTextSize(36);
        ts.setFactory(this);// 指定转换器的 ViewSwitcher.ViewFactory
        // 设置淡入和淡出的动画效果
        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
        ts.setInAnimation(in);
        ts.setOutAnimation(out);
        btn.setOnClickListener(new Button.OnClickListener(){

			public void onClick(View v) {
				String str = String.valueOf(new Random().nextInt());
				ts.setText(str);
				tv2.setText(str);
			}
        	
        });
    }
      // 重写 ViewSwitcher.ViewFactory 的 makeView(),返回一个 View
	public View makeView() {
		TextView tv = new TextView(this);
		tv.setTextSize(36);
		return tv;
	}
}
分享到:
评论

相关推荐

    Android TextSwitcher(文字交换器)的使用

    在Android开发中,TextSwitcher是一个非常实用的控件,主要用于在界面上动态地切换文本内容,常用于显示一些简短的更新信息或者状态提示。它继承自ViewSwitcher类,具备了动画效果,使得文本的切换更加平滑自然。本...

    Android 中textSwitcher与imageSwitcher的使用

    在Android开发中,`TextSwitcher`和`ImageSwitcher`是两种非常实用的视图切换组件,主要用于在界面上动态地展示文本或图像。它们都继承自`ViewSwitcher`类,提供了一种平滑过渡的效果,使得界面在内容更新时更加流畅...

    Android TextSwitcher Demo

    本实例"Android TextSwitcher Demo"旨在展示如何有效地使用`TextSwitcher`来实现文本的平滑过渡。 `TextSwitcher`继承自`ViewSwitcher`类,它提供了内置的淡入淡出动画,使得文本在更新时不会突然跳变,而是以一种...

    android-TextSwitcher-master.zip

    android-TextSwitcher-master.zip对你的学习会有帮助的

    Android TextSwitcher文本切换器和ViewFlipper使用详解

    本文为大家分享了Android TextSwitcher文本切换器的使用,供大家参考,具体内容如下 1.TextSwitcher  使用: 应用分为三步: 1.得到 TextSwitcher 实例对象  TextSwitcher switcher = (TextSwitcher) ...

    TextSwitcher

    `TextSwitcher`是Android平台中的一个特殊视图组件,主要设计用于在界面上动态地切换文本内容。它属于`ViewSwitcher`家族的一部分,这些组件通常用来在用户交互后或者按照一定时间间隔自动切换不同的视图。在`...

    Android 上下滚动TextSwitcher实例详解

    在Android开发中,TextSwitcher是一个非常有用的组件,它用于在界面上动态切换文本内容,通常搭配动画效果,使得文本的切换更为流畅和吸引人。本文将深入探讨如何在Android中实现上下滚动的TextSwitcher实例。 首先...

    自定义TextSwitcher实现文本自动垂直滚动

    在Android开发中,TextSwitcher是一个非常有用的组件,它用于在两个TextView之间切换文本,通常用于显示动态更新的信息。然而,标准的TextSwitcher仅支持水平滚动,如果想要实现文本的垂直滚动效果,我们就需要对其...

    Android TextSwitcher实现文字上下翻牌效果(铜板街)

    在Android开发中,TextSwitcher是一个非常有用的控件,它主要用于在界面上展示文本的切换效果,例如在应用启动时的欢迎语、消息提示或广告轮播等场景。本篇文章将详细讲解如何利用TextSwitcher实现类似铜板街的文字...

    图片轮播 文字轮播 ImageSwitcher TextSwitcher

    ImageSwitcher和TextSwitcher是Android SDK提供的一对控件,专门用于实现这样的动态切换效果。下面我们将深入探讨这两个控件的工作原理、使用方法以及实际应用中的注意事项。 首先,ImageSwitcher是用于在两个...

    TextSwitcher实现文字上下左右滚动

    在Android开发中,`TextSwitcher` 是一个用于创建文本切换动画效果的视图组件,常用于实现广告条或信息提示区域的文字上下左右滚动效果。它继承自`ViewSwitcher`,并内置了平滑过渡的动画,使得文本在切换时更加自然...

    Android开发实现自动切换文字TextSwitcher功能示例

    在Android开发中,TextSwitcher是一个非常实用的控件,它是ViewSwitcher的子类,专为在界面上实现文本内容自动切换而设计。通过TextSwitcher,开发者可以在多个文本字符串间平滑地进行切换,通常用于显示动态更新或...

    textswitcher的官方demo

    在Android开发中,TextSwitcher是一个非常有用的视图组件,它允许开发者实现文本内容的平滑切换,通常伴有动画效果,提升用户体验。本教程将详细讲解`TextSwitcher`的官方示例及其核心知识点。 首先,`TextSwitcher...

    TextSwitcher垂直滚动文字广告demo

    在Android开发中,TextSwitcher是一个非常实用的控件,常用于实现文本的动态切换效果,比如我们在京东、淘宝的搜索框中看到的那种滚动小广播。这个“TextSwitcher垂直滚动文字广告demo”是一个示例项目,展示了如何...

    TextSwitcher:仿京东、淘宝滚动小广播,实现文字轮播滚动

    在Android开发中,TextSwitcher是一个非常实用的控件,常用于实现文本的动态切换效果,比如我们在京东、淘宝等电商应用中常见的滚动小广播。这个控件属于ViewSwitcher家族,是Android SDK提供的一种视图切换器,专门...

    Android-仿照Google在卡片上滚动显示最新评论的TextSwitcher

    本篇文章将深入探讨如何在Android中实现这样一个功能,主要使用TextSwitcher控件。 TextSwitcher是Android SDK提供的一种特殊的View,它主要用于在两个文本之间平滑地切换。这个控件特别适合用于动态更新内容,例如...

    TextView实现文字的跑马灯效果&TextSwitcher实现文字竖直飞出和飞入

    `TextView`和`TextSwitcher`都是Android SDK提供的重要组件,它们用于显示文本信息。在这个话题中,我们将深入探讨如何利用`TextView`实现跑马灯效果以及如何通过`TextSwitcher`实现文字竖直飞出和飞入的动画效果。 ...

Global site tag (gtag.js) - Google Analytics