ViewSwitcher的简单使用

遇到新的需求:

     在页面中点击下一步的时候再同一个activity中进行页面的切换显示

所以简单的时候ViewSwitcher就搞定了,源码:

Activity代码:

package com.gupiaobang.app;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ViewSwitcher;

public class RegisterActivity extends Activity{

	private ViewSwitcher vs_content;
	
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_module_register_first);
	    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.public_title);  
        initView();
    }
    
    public void initView(){
    	vs_content = (ViewSwitcher) findViewById(R.id.vs_content);
		//使用者这个方法就可以进行要全面的切换了
		vs_content.setDisplayedChild(1); //显示第二个页面
			
    }
    
}
页面布局:

<LinearLayout 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:orientation="vertical"
     >
    <!-- 注册界面第一个页面 -->
	 <ViewSwitcher 
	     android:id="@+id/vs_content"
	     android:layout_width="match_parent"
    	 android:layout_height="match_parent"
    	 android:inAnimation="@android:anim/slide_in_left"
         android:outAnimation="@android:anim/slide_out_right"
	     >
		 <!-- 将要切换显示的页面放入到ViewSwitcher中,然后在activity中就可以通过
				setDisplayedChild进行切花View的显示了
		 -->
	     <!-- 第一页 -->
	     <LinearLayout 
	        android:layout_width="match_parent"
    		android:layout_height="match_parent"
    		android:orientation="vertical"
	         >
		    <!-- 确认 -->
		    <Button 
		        android:id="@+id/r_next"
		        android:layout_width="fill_parent"
	    	 	android:layout_height="wrap_content"
	    	 	android:layout_marginTop="@dimen/margin_small"
	    	 	android:paddingTop="@dimen/padding_small"
    			android:paddingBottom="@dimen/padding_small"
	    	 	style="@style/text_red_big"
	    	 	android:background="@drawable/button_press"
	    	 	android:text="@string/r_next"
		        />
	     </LinearLayout>
	     <!-- 第二页 -->
	     <LinearLayout 
	        android:layout_width="match_parent"
    		android:layout_height="match_parent"
    		android:orientation="vertical"
	         >
			    <!-- 确认 -->
			    <Button 
			        android:id="@+id/r_finish"
			        android:layout_width="fill_parent"
		    	 	android:layout_height="wrap_content"
		    	 	android:paddingTop="@dimen/padding_small"
    				android:paddingBottom="@dimen/padding_small"
		    	 	android:layout_marginTop="@dimen/margin_max"
		    	 	style="@style/text_red_big"
		    	 	android:background="@drawable/button_press"
		    	 	android:text="@string/r_finish"
			        />
		  </LinearLayout>
	 </ViewSwitcher>
	
</LinearLayout>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值