Android bitmap image size in XML

后端 未结 8 1028
情书的邮戳
情书的邮戳 2020-12-08 03:34

In my XML file, I\'m using bitmap as the following


Here t

相关标签:
8条回答
  • 2020-12-08 04:12

    this one I use for resize my mipmap on to my launch screen.

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
        <item android:drawable="@color/colorPrimary"/>
        <item
            android:width="200dp"
            android:height="200dp"
            android:gravity="center">
            <bitmap
                android:gravity="fill"
                android:src="@mipmap/ic_launcher"
                android:mipMap="true"/>
        </item>
    </layer-list>
    
    0 讨论(0)
  • 2020-12-08 04:13

    Try to do it this way, this worked for me:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
      <item
        android:width="30dp"
        android:height="30dp"
        android:gravity="center"
      >
            <bitmap
           android:src="@drawable/screen"/>
      </item>
    
    </layer-list>
    
    0 讨论(0)
  • 2020-12-08 04:19

    Complete Solution just copy paste and change the Image Path

      <?xml version="1.0" encoding="utf-8"?>
    
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
     <item
        android:gravity="center"
        android:width="286dp"
        android:height="176dp">
    
        <bitmap
            android:src="@drawable/logo"
            android:gravity="fill_horizontal|fill_vertical" />
       </item>
     </layer-list>
    
    0 讨论(0)
  • 2020-12-08 04:20

    Just use

    <item
        android:width="200dp"
        android:height="200dp"
        android:drawable="@drawable/splash_background"
        android:gravity="center" />
    

    instead

    <item
        android:left="200dp"
        android:right="200dp">
    
        <bitmap
            android:src="@drawable/splash_background"
            android:gravity="center" />
    
    </item>
    
    0 讨论(0)
  • 2020-12-08 04:23

    Although there is no width and height parameters for bitmap, you can set bitmap size using gravity and item width/height.

    <item
        android:width="230dp"
        android:height="70dp">
        <bitmap
            android:gravity="fill_horizontal|fill_vertical"
            android:src="@drawable/screen" />
    </item>
    

    You can set item width and height and scale bitmap inside of it using gravity.

    I know this is old question but maybe someone will find it useful.

    WARNING:

    As already mentioned in comments, this method ONLY works with API level 23 (Android 6.0) and up.

    0 讨论(0)
  • 2020-12-08 04:32

    I just resized the image manually then it works for me

    0 讨论(0)
提交回复
热议问题