android xml drawable image on full screen background

后端 未结 5 731
旧时难觅i
旧时难觅i 2021-02-08 04:33

I need an xml drawable (for a cordova splash screen) in android. I Want to display a transparent logo centered on the screen (without stretching), while the rest of the screen h

相关标签:
5条回答
  • 2021-02-08 05:13

    do this way,

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white" >//Set background color
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:adjustViewBounds="true"
                android:src="@drawable/splash_logo" />//set logo 
    
        </RelativeLayout>
    
    0 讨论(0)
  • 2021-02-08 05:23

    No need to use other relative layout for background color. You can do it using single ImageView like:

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@drawable/noise"
        android:scaleType="centerInside"
        android:background="@android:color/black" />
    
    0 讨论(0)
  • 2021-02-08 05:24

    I found the solution myself:

    <?xml version="1.0" encoding="utf-8"?>
    
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <color android:color="#FFFF"></color>
        </item>
        <item>
            <bitmap
                android:src="@drawable/splashscreen"
                android:gravity="center_horizontal|center_vertical"
                />
        </item>
    </layer-list>
    

    Android studio shows the layout still wrong - but it works on the device as expected.

    To all posters, suggesting adding a layout-xml file: As I stated in the question, I don't have the possibility to do that, since this drawable gets included from Cordova. I don't have control over the used layout around this drawable.

    0 讨论(0)
  • 2021-02-08 05:25

    You can use following code for your need:

       <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item android:drawable="@color/bg_color"/>
        <item>
            <bitmap
                android:gravity="center|bottom|clip_vertical"
                android:src="@drawable/your_image" />
        </item>
    
    </layer-list>
    
    0 讨论(0)
  • 2021-02-08 05:34
    <?xml version="1.0" encoding="UTF-8"?>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
            android:src="@drawable/splash" 
            android:gravity="fill_horizontal|fill_vertical" />
    
    0 讨论(0)
提交回复
热议问题