如何在Android中从一个布局切换到另一个布局

时间:2011-07-17 02:30:00

标签: android layout progress-bar

我的想法是当我打开我的应用程序时,带有progressBar(确定)的布局将显示5秒钟。 5秒后,此布局将被包含一些按钮的另一个布局替换。 怎么做。 Plz帮助我......

4 个答案:

答案 0 :(得分:1)

尝试setContentView(R.layout.secondLayout);

如果这不起作用,您还可以将所有视图放在一个布局下,并将按钮的可见性设置为true,并在5秒后将进度条的可见性设置为false。

答案 1 :(得分:1)

您可以在ViewFlipper

下的一个布局中定义所有两个布局属性
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/lah"
    >
    <ViewFlipper 
        android:id="@+id/flipper"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent" 
        >

       <LinearLayout 
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/first_layout">
         .
         .

         .

       </LinearLayout> 

       <LinearLayout 
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/second_layout">
         .
         .

         .

       </LinearLayout> 

   </ViewFlipper 
</LinearLayout> 

然后在你的java程序中创建一个ViewFlipper对象。

    ViewFlipper vf = (ViewFlipper) findViewById( R.id.flipper);

并致电

    vf.showNext();

您还可以应用似乎从右向左切换布局的动画。感谢...

    vf.setInAnimation(AnimationUtils.loadAnimation( getApplicationContext(), R.anim.right_in ));
    vf.setOutAnimation( AnimationUtils.loadAnimation( getApplicationContext(), R.anim.left_out ));
    vf.showNext();

答案 2 :(得分:0)

您可以使用ViewAnimator

答案 3 :(得分:0)

在LinearLayout或相对布局中,如果为progess bar和第二个包含按钮声明两个布局布局,则在完成进度条进度时,只需将进度条布局可见性设置为GONE,并将布局可见性按钮设置为VISIBLE。 首先按钮布局可见性应该为GONE。