我有一个全屏PNG,我想显示在飞溅。只有一个错误,我也不知道 每个可绘制文件夹(ldpi、mdpi、hdpi和xhdpi)的大小。我的应用程序应该在所有的手机和平板电脑上运行良好和美观。我应该创建什么大小(以像素为单位),以便在所有屏幕上显示良好的飞溅?
当前回答
使用PNG并不是一个好主意。实际上,就性能而言,这是昂贵的。 您可以使用可绘制的XML文件,例如,Facebook的背景。
这将帮助你平滑和加速你的性能,并为标志使用。9补丁图像。
其他回答
编辑的解决方案,将使您的SplashScreen在包括API21到API23在内的所有api上看起来很棒
如果你只针对APIs24+,你可以直接在它的xml文件中缩小你的矢量绘制,如下所示:
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="640"
android:viewportHeight="640"
android:width="240dp"
android:height="240dp">
<path
android:pathData="M320.96 55.9L477.14 345L161.67 345L320.96 55.9Z"
android:strokeColor="#292929"
android:strokeWidth="24" />
</vector>
在上面的代码中,我将在640x640画布上绘制的可绘制对象缩放为240x240。然后我把它放在我的启动画面中,就像这样,效果很好:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"
android:paddingBottom="20dp" android:paddingRight="20dp" android:paddingLeft="20dp" android:paddingTop="20dp">
<!-- The background color, preferably the same as your normal theme -->
<item>
<shape>
<size android:height="120dp" android:width="120dp"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
<!-- Your product logo - 144dp color version of your app icon -->
<item
android:drawable="@drawable/logo_vect"
android:gravity="center">
</item>
</layer-list>
我的代码实际上只画了底部图片中的三角形但在这里你可以看到你可以用它实现什么。与使用位图时得到的像素化边缘相比,分辨率终于变得很棒了。所以无论如何都要使用一个可绘制的矢量(有一个叫做vectr的网站,我曾经用它来创建我的矢量,而不需要下载专门的软件)。
编辑,以使它也API21-22-23工作
虽然上述解决方案适用于运行API24+的设备,但在安装了运行API22的设备后,我真的很失望。我注意到溅水幕再次试图填满整个视野,看起来像一坨屎。在撕了半天眉毛之后,我终于靠意志力勉强找到了解决办法。
you need to create a second file named exactly like the splashscreen xml (lets say splash_screen.xml) and place it into 2 folders called drawable-v22 and drawable-v21 that you will create in the res/ folder (in order to see them you have to change your project view from Android to Project). This serves to tell your phone to redirect to files placed in those folders whenever the relevant device runs an API corresponding to the -vXX suffix in the drawable folder, see this link. place the following code in the Layer-list of the splash_screen.xml file that you create in these folders:
<item>
<shape>
<size android:height="120dp" android:width="120dp"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
<!-- Your product logo - 144dp color version of your app icon -->
<item android:gravity="center">
<bitmap android:gravity="center"
android:src="logo_vect"/>
</item>
For some reason for these APIs you have to wrap your drawable in a bitmap in order to make it work and jet the final result looks the same. The issue is that you have to use the aproach with the aditional drawable folders as the second version of the splash_screen.xml file will lead to your splash screen not being shown at all on devices running APIs higher than 23. You might also have to place the first version of the splash_screen.xml into drawable-v24 as android defaults to the closest drawable-vXX folder it can find for resources. hope this helps
Density buckets
LDPI 120dpi .75x
MDPI 160dpi 1x
HDPI 240dpi 1.5x
XHDPI 320dpi 2x
XXHDPI 480dpi 3x
XXXHDPI 640dpi 4x
px / dp = dpi / 160 dpi
根据Lucas Cerro的回答,我使用Android文档中的比率,使用答案中的基线来计算尺寸。我希望这能帮助其他人来到这个帖子!
xxxsize (xxxhdpi): 1280x1920 (4.0x) xxhdpi: 960x1440 (3.0x) Xlarge (xhdpi): 640x960 (2.0x) 大尺寸(hdpi): 480x800 (1.5x) 中(mdpi): 320x480 (1.0x基线) 小(ldpi): 240x320 (0.75x)
肖像
LDPI: 200x320px
MDPI: 320x480px
HDPI: 480x800px
XHDPI: 720px1280px
景观
LDPI: 320x200px
MDPI: 480x320px
HDPI: 800x480px
XHDPI: 1280x720px
竖屏模式
MDPI是320x480 dp = 320x480px (1x)
LDPI是0.75 x MDPI = 240x360px
HDPI是1.5 x MDPI = 480x720px
XHDPI是2 × MDPI = 640x960px
XXHDPI是3 x MDPI = 960x1440px
XXXHDPI是4 x MDPI = 1280x1920px
横屏模式
MDPI是480x320 dp = 480x320px (1x)
LDPI为0.75 x MDPI = 360x240px
HDPI是1.5 x MDPI = 720x480px
XHDPI是2 × MDPI = 960x640px
XXHDPI是3 x MDPI = 1440x960px
XXXHDPI是4 x MDPI = 1920x1280px
编辑:
如果你是在2019年以上阅读这篇文章,我建议你使用Lottie作为启动画面
推荐文章
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 按钮背景是透明的
- 在Mac OS X上哪里安装Android SDK ?
- 我如何获得图像缩放功能?
- 在Android应用程序中显示当前时间和日期
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点