遇到新的需求:
在页面中点击下一步的时候再同一个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>