[Android]ViewSwitcher使用范例

正文

  一、简介

    ViewSwitcher适用于两个视图带动画效果的切换。这里实现两个视图切换的功能,并附带滑屏效果。

 

  二、截图

    视图一

    视图二

 


 

  二、范例代码

    带动画效果的切换视图一和视图二。

    xml

    <ViewSwitcher android:layout_alignParentBottom="true"
        android:persistentDrawingCache
="animation" android:id="@+id/bottom"
        android:layout_width
="match_parent" android:inAnimation="@android:anim/slide_in_left"
        android:outAnimation
="@android:anim/slide_out_right" android:layout_height="122.0dip">
        
<RelativeLayout android:layout_width="fill_parent"
            android:layout_gravity
="bottom" android:layout_marginBottom="12.0dip"
            android:id
="@+id/lyBottom" android:layout_height="wrap_content">
            
<Button android:id="@+id/btn_pre" android:text="上一步"
                android:layout_width
="wrap_content" android:layout_height="wrap_content"
                android:layout_centerVertical
="true" android:layout_toLeftOf="@+id/btn_middle"
                android:layout_marginRight
="150.0dip" />
            
<Button android:id="@+id/btn_middle" android:layout_width="wrap_content"
                android:layout_centerInParent
="true" android:onClick="onClick" android:visibility="invisible"
                android:textSize
="22.0sp" 
                android:layout_height
="wrap_content"></Button>
            
<Button android:id="@+id/btn_next"  android:text="下一步"
                android:layout_width
="wrap_content" android:layout_height="wrap_content"
                android:layout_centerVertical
="true" android:layout_toRightOf="@+id/btn_middle"
                android:layout_marginLeft
="150.0dip" />
        
</RelativeLayout>
        
<RelativeLayout android:layout_width="fill_parent"
            android:layout_gravity
="bottom" android:layout_height="wrap_content"
            android:orientation
="horizontal">
            
<ImageView android:src="@drawable/cube" android:id="@+id/btn_reinsure"
                android:layout_width
="wrap_content" android:layout_height="wrap_content"
                android:layout_marginLeft
="150.0dip"></ImageView>
            
<ImageView android:src="@drawable/cyddz" android:id="@+id/btn_identity"
                android:layout_width
="wrap_content" android:layout_height="wrap_content"
                android:layout_toRightOf
="@+id/btn_reinsure"
                android:layout_marginLeft
="124.0dip"></ImageView>
            
<ImageView android:src="@drawable/cykvmce" android:id="@+id/btn_insure_query"
                android:layout_toRightOf
="@+id/btn_identity" android:layout_width="wrap_content"
                android:layout_height
="wrap_content" android:layout_marginLeft="140.0dip"></ImageView>
            
<ImageView android:src="@drawable/m8gprs" android:id="@+id/btn_review"
                android:layout_toRightOf
="@+id/btn_insure_query"
                android:layout_width
="wrap_content" android:layout_height="wrap_content"
                android:layout_marginLeft
="140.0dip"></ImageView>
            
<ImageView android:src="@drawable/th_appshareth"
                android:layout_toRightOf
="@+id/btn_review"
                android:layout_width
="wrap_content" android:layout_height="wrap_content"
                android:layout_marginLeft
="130.0dip"></ImageView>
        
</RelativeLayout>
    
</ViewSwitcher>

      代码说明:

        1. 这里使用系统自带的切换效果@android:anim/slide_in_left和@android:anim/slide_out_right。

        2. 请大家自行准备测试图片

    java

        bottom = (ViewSwitcher) findViewById(R.id.bottom);
        
//切换为第一个
        bottom.setDisplayedChild(0);
        
//切换到下一个
        
//bottom.showNext()


本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/658874,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值