1

Ich habe ein Bild als Hintergrund von LinearLayout in Splash-Screen-Aktivität verwendet, aber es zeigen nicht für den Bildschirm geeignet. Ich weiß nicht, wie man Attribut dafür benutzt, es zu dehnen.Splash Screen Bildhintergrund in LinearLayout nicht passen

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_splash" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.myproject.SplashActivity" 
    android:orientation="horizontal" 
    android:background="@drawable/my_image_background"> 

</LinearLayout> 

Antwort

1

Der richtige Weg ist dies so ist dies stattdessen zu verwenden, in Ihrem styles.xml hinzufügen:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="android:windowBackground">@drawable/splash</item> 
</style> 

Und in Ihrer Manifest-Datei hinzufügen, diese

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

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

und @ ziehbar/Splash könnte wie sein

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"> 
    <!-- The background color, preferably the same as your normal theme --> 
    <item android:drawable="@drawable/splashscreen"/> 
    <!-- Your product logo - 144dp color version of your app icon --> 
    <item> 
     <bitmap 
      android:src="@drawable/splash_logo" 
      android:gravity="center"/> 
    </item> 
</layer-list> 
1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/dighsplash"> 
</LinearLayout> 

versuchen Sie diesen Weg.

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_splash" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.myproject.SplashActivity" 
    android:orientation="horizontal" 
    android:background="@drawable/my_image_background"> 
    <ImageView 
     android:scaleType="fitXY" 
     android:src="@drawable/my_image_background" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</LinearLayout> 

Verwenden Image und Verwendungs-Attribut scaleType .Dieses automatisch jede Bildschirmauflösung passt.

----- ------- aktualisieren

Als Anders als das von Ahamed vorgeschlagen, wenn Sie mehr Ansichten in das Layout hinzufügen möchten, Es ist besser zu nutzen RelativeLayout (Seit es würde Ihre Ansichten stapeln). Betrachten Sie die folgende Implementierung von RelativeLayout.

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_splash" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <ImageView 
      android:scaleType="fitXY" 
      android:src="@drawable/my_image_background" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
      <!-- Add other views depending on your screen specs --> 
    </RelativeLayout> 
+0

er braucht Hintergrundbild. Wenn er die Bildansicht in Linearlayout einstellt, wie kann er den Rest der Layouts platzieren? Kannst du bitte Erklären? – Noorul

+0

@Ahamed Ich gab nur ein generisches Beispiel für Splash-Screen. Man kann RelativeLayout anstelle von LinearLayout verwenden, um mit dem von Ihnen angegebenen Problem fertig zu werden. –

+1

Ja. du hast es geschafft. ich schätze es. aber, einige neue grundlegende Programmierer wissen nicht, was als nächstes zu tun ist. Also, geben Sie mehr Informationen über Ihre Antwort, dann werden Sie einen besseren Ruf bekommen. – Noorul

1

Besseres Image für Bild zu verwenden, so habe ich das Layout verändert, wie unten & shoul es wie erwartet.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_splash" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    tools:context="com.myproject.SplashActivity"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/my_image_background" /> 

</LinearLayout> 
0

Versuchen Sie folgendes zu folgen, wenn scaleType = "fitxy" nicht mit imageview funktioniert.

android: fitSystemWindows = "true"

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_splash" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.myproject.SplashActivity" 
android:orientation="horizontal" 
android:background="@drawable/my_image_background" 
android:fitSystemWindows="true"> 
+2

was ist hier nötig fillviewport = true. Ich denke, es ist Scrollview-Eigenschaft. bearbeite deine Antwort. – Noorul

+0

Ja, Sie haben Recht. Vielen Dank – Pehlaj

1

verwenden:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_splash" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.myproject.SplashActivity" 
android:fitSystemWindows="true" 
android:orientation="horizontal" 
android:scaleType="fitXY" 
android:background="@drawable/my_image_background"> 

Dieser Code auf jeden Fall Ihren Bildschirm passen.

1

überprüfen Zunächst wird das Bild my_image_background hat keine weißen Flecken an den Seiten .if nicht, Ihr Code funktioniert ... sonst kann u diesen Code versuchen zu

<?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/activity_splash" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context="com.myproject.SplashActivity" 
      android:orientation="vertical" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/my_image_background"> 

     </RelativeLayout> 

prüfen dies auch aus ::: Showing Splash screen in android apps