ViewSwitcher

ViewSwitcher,可以在两个View之间切换,并且可以带一些简单的切换动画,它只能有两个子View。

可以用来当splashscreen,在显示图片的时候加载数据,数据加载完后显示另一个View。

xml文件

<ViewSwitcher 
    android:id="@+id/container"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:inAnimation="@android:anim/slide_in_left"
    android:outAnimation="@android:anim/slide_out_right"
    tools:context=".ViewSwitcher" >

    <ImageView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >
    
	    <TextView
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        android:background="#66ccff"
	        android:text="@string/hello_world" />
	    
    </LinearLayout>

</ViewSwitcher>
activity文件

private android.widget.ViewSwitcher vs = null;
private int resid[] = {R.drawable.ic_1, R.drawable.ic_2, R.drawable.ic_3, R.drawable.ic_4, R.drawable.ic_5};
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_view_switcher);
	
	vs = (android.widget.ViewSwitcher)findViewById(R.id.container);
	vs.getChildAt(0).setBackgroundResource(resid[(int) (Math.random()*4)]);
	mHandler.sendEmptyMessageDelayed(1, 1000);
}

Handler mHandler = new Handler(){
	public void handleMessage(Message msg){
		vs.showNext();
	}
};

之前使用runnable来延迟切换,却没反应,一直在第一个子View。不知道是不是和其他线程里不能更新UI有关系,但是后来用了handler,把sendMessage放在单独线程里,还是不能切换,不知道什么原因,网上资料还没翻着。


参考资料:Android 中文API (61) —— ViewSwitcher

http://www.cnblogs.com/over140/archive/2011/09/03/2121526.html

http://blog.youkuaiyun.com/hitlion2008/article/details/7969016#

http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1112/545.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值