Android:TextSwitcher、imageSwitcher

简介:

TextSwitcher只能放两个textview控件。

主要属性设置:

1
2
android:inAnimation= "@anim/setanimin"
android:outAnimation= "@anim/setanimout"


XML代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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"
     tools:context= ".MainActivity"  >
     <TextSwitcher
         android:id= "@+id/textSwitcher1"
         android:layout_width= "match_parent"
         android:layout_height= "120dp"
         android:inAnimation= "@anim/setanimin"
         android:outAnimation= "@anim/setanimout"
         android:layout_alignParentLeft= "true"
         android:layout_alignParentTop= "true"  >
         <TextView
             android:id= "@+id/textView2"
             android:layout_width= "match_parent"
             android:layout_height= "wrap_content"
             android:text= "Large Text"
             android:textAppearance= "?android:attr/textAppearanceLarge"  />
         <TextView
             android:id= "@+id/textView1"
             android:layout_width= "match_parent"
             android:layout_height= "wrap_content"
             android:text= "Large Text"
             android:textAppearance= "?android:attr/textAppearanceLarge"  />
     </TextSwitcher>
</RelativeLayout>


启动动画,java代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
textSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher1);
action =  new  Runnable()
{
     @Override
     public  void  run()
     {
         num++;
         textSwitcher.setText(ss[ num % ss.length] ); //通过setText启动动画
         textSwitcher.postDelayed(action ,  1000 );
     }
};
textSwitcher.postDelayed(action ,  1000 );



imageSwitcher同理:

1
2
3
4
5
6
7
8
9
10
11
12
imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
         action =  new  Runnable()
         {
             @Override
             public  void  run()
             {
                 num++;
                 imageSwitcher.setImageResource(mPhoto[num %  6 ]);
                 imageSwitcher.postDelayed(action ,  5000 );
             }
         };
         imageSwitcher.postDelayed(action ,  100 );




本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1226237,如需转载请自行联系原作者

目录
相关文章
|
Android开发
Android零基础入门第55节:ImageSwitcher和TextSwitcher使用
原文:Android零基础入门第55节:ImageSwitcher和TextSwitcher使用     上一期我们了解了ViewAnimator组件和ViewSwitcher组件的使用,你都掌握了吗?本期一起来学习ViewSwitcher的两个子组件ImageSwitcher和TextSwitcher。
1596 0
|
XML Android开发 数据格式
我的Android进阶之旅------&gt;Android之Gallery和GridView两种方式与ImageSwitcher实现带预览的和幻灯片方式的两种图片浏览器
一、简介 a.GridView(网络视图)的功能和用法 b.ImageSwitcher(图形切换器)的功能和用法 c.Gallery(画廊视图)的功能和用法 二、通过一个实例来学习Gallery、GridView和I...
1233 0