【问题标题】:Layout : Splash screen background is still showing when new layout comes布局:当新布局出现时,启动画面背景仍然显示
【发布时间】:2013-03-22 20:07:45
【问题描述】:

我的布局有问题。在我的活动中,我首先显示一个启动屏幕,然后根据某些条件我需要显示不同的布局。当我显示一个布局时,它看起来像透明的白色(如启动视图),而另一个则可以,因为它的背景颜色匹配用它。 当我按下透明白色视图(文本视图)时,它看起来很正常。也就是说,它在按下和释放不同视图时充当按钮。

我尝试提供背景颜色,但仍然存在问题。不幸的是,我只需要为该视图提供白色。

谁能帮我更改新布局中显示的透明白色

这是有背景问题的视图布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/white"  
 >

<ScrollView 
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_marginLeft="5dp"
 android:layout_marginRight="5dp"
 >
 <RelativeLayout 
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
     >
   <TextView
     android:id="@+id/abc"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"

      />
     </RelativeLayout>   
 </ScrollView>

<RelativeLayout 
     android:id="@+id/button_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"

    android:paddingBottom="5dp"
    >

<Button 
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:text="@string/btn1"
    android:background="@drawable/btn1"


    />
 <Button 
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="@string/btn2"
    android:background="@drawable/btn2" 
   />

</RelativeLayout>

在代码中

oncreate(){
setcontentview(splashscreen)
setview()
}

void setview(){
if(condition1){
            setContentView(R.layout.a1);

}
else{
       setContentView(R.layout.a2);
}
}

【问题讨论】:

  • 你完成你的启动画面活动了吗?
  • 您是否使其他视图无效?为什么不将其他视图设置为不可见,而将您正在使用的视图设置为可见。在这个问题上需要更多的肉。
  • @JibranKhan 在主要活动飞溅中使用 .我需要更改同一活动中的视图而不是新的视图
  • @digiholic 如何使视图无效?
  • Korcholis 的回答大致也是我做初始屏幕的方式。 Sjk,对不起,当我最初发布代码时,代码没有启动。也许您可以根据它的视图类型设置您的 splashscreen.setVisibility(View.INVISIBLE) 。我的意思是,也许屏幕并没有移除旧视图,只是在它上面绘制。

标签: android layout splash-screen


【解决方案1】:

为什么不等到启动画面结束后才转移到另一个活动?喜欢this。只是为了这样,我在这里复制该页面的代码:

package com.itcuties.tutorial.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;


public class SplashActivity extends Activity {

   private static String TAG = SplashActivity.class.getName();
   private static long SLEEP_TIME = 5;    // Sleep for some time

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar

      setContentView(R.layout.splash);

      // Start timer and launch main activity
      IntentLauncher launcher = new IntentLauncher();
      launcher.start();
   }

   private class IntentLauncher extends Thread {
      @Override
      /**
       * Sleep for some time and than start new activity.
       */
      public void run() {
         try {
            // Sleeping
            Thread.sleep(SLEEP_TIME*1000);
         } catch (Exception e) {
            Log.e(TAG, e.getMessage());
         }

         // Start main activity
         Intent intent = new Intent(SplashActivity.this, MainActivity.class);
         SplashActivity.this.startActivity(intent);
         SplashActivity.this.finish();
      }
   }
}

【讨论】:

    猜你喜欢
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多