Android启动画面不会全屏显示图像

时间:2016-08-26 10:56:36

标签: android

我的Android应用程序中包含以下代码。

我的res / values / styles.xml:

   <style name="FullScreen" parent="@style/Theme.AppCompat.Light">
   <item name="windowNoTitle">true</item>
   <item name="windowActionBar">false</item>
   <item name="android:windowFullscreen">true</item>
   <item name="android:windowContentOverlay">@null</item>
   <item       name="android:windowBackground">@drawable/background_splash</item>
   </style>

RES /抽拉/ background_splash.xml:

  <item

     android:drawable="@color/colorPrimaryDark"/>

   <item>
      <bitmap
        android:gravity="center"
        android:src="@mipmap/image1"/>
   </item>

的AndroidManifest.xml:

    <activity
      android:name=".SplashActivity"
      android:theme="@style/FullScreen">
    <intent-filter>
      <action android:name="android.intent.action.MAIN"/>

      <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

SplashActivity.java:

    public class SplashActivity extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 5000;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_splash);

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent i = new Intent(SplashActivity.this,  MainActivity.class);
            startActivity(i);
            finish();
        }
        }, SPLASH_TIME_OUT);
       }
    }

我在res文件夹中存在具有适当分辨率/大小的image1。但是启动画面不会显示覆盖全屏的图像,而是仅在屏幕的某些部分显示缩小的尺寸。能否请您提出建议。我查看了一些网站上提出的一些建议,但没有帮助。

6 个答案:

答案 0 :(得分:6)

res / drawable / background_splash.xml 中,更改 android:gravity 你可以使用“填充”,在我的情况下我只使用“top | fill_horizo​​ntal”进行水平填充,选择你想要的组合。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:drawable="@color/White"/>

   <item>
       <bitmap
           android:gravity="center"
           android:src="@drawable/splash"/>
   </item>
</layer-list>

答案 1 :(得分:3)

我已完成此计划。这是你想要的?这是你的主要XML

500

和mainActivity

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res  
/android"
android:layout_width="match_parent"
android:background="@drawable/android"
android:layout_height="match_parent">

和Manifest

 public class MainActivity extends AppCompatActivity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(MainActivity.this, YourNextActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}}

答案 2 :(得分:1)

使用主题的父母

父=&#34; @风格/ Theme.AppCompat.Light.NoTitleBar.Fullscreen&#34;

答案 3 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:src="@drawable/image" />
</LinearLayout

并使用

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

在您的活动代码中。

答案 4 :(得分:0)

确保您的splash xml文件没有任何类型的填充。如果有,请删除。

答案 5 :(得分:0)

activity_splash.xml的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    tools:context=".SplashActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/icon"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        />
</android.support.constraint.ConstraintLayout>

Splash.java的代码

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_splash);
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(SplashActivity.this,MainActivity.class);
                startActivity(i);
                finish();
            }
        },2000);
    }
}