我有一个全屏PNG,我想显示在飞溅。只有一个错误,我也不知道 每个可绘制文件夹(ldpi、mdpi、hdpi和xhdpi)的大小。我的应用程序应该在所有的手机和平板电脑上运行良好和美观。我应该创建什么大小(以像素为单位),以便在所有屏幕上显示良好的飞溅?
当前回答
前段时间我创建了一个支持维度的excel文件 希望这对某些人有所帮助
老实说,我失去了想法,但它指的是另一个屏幕功能的大小(不仅仅是密度) https://developer.android.com/guide/practices/screens_support.html 如果有错误,请告诉我
Link1: dimensions.xlsx
Link2: dimensions.xlsx
其他回答
使用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
我已经搜索了最好最简单的答案来制作9-patch image。现在制作9个补丁映像是最简单的任务。
从https://romannurik.github.io/AndroidAssetStudio/index.html,您可以制作一个9补丁图像的所有分辨率- XHDPI,HDPI,MDPI,LDPI只需点击一下。
根据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)
竖屏模式
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启动画面图像大小适合所有设备
- 获得当前运行我的应用程序的手机的Android API级别
- Android SDK管理器无法打开
- 如何将DecimalFormat的小数分隔符从逗号更改为点/点?
- Android谷歌maps java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion
- android中textview的圆角
- 在Android中,对话框被取消或被取消有什么区别?
- 在ScrollView触摸处理中的HorizontalScrollView
- 何时在Android中使用RxJava,何时使用Android架构组件中的LiveData ?
- 如何在Android项目中使用ThreeTenABP
- 指定的子节点已经有一个父节点。你必须先在子对象的父对象上调用removeView() (Android)
- 我的Android设备没有出现在adb设备列表中
- 在没有安装apk的情况下获取Android .apk文件的VersionName或VersionCode
- Fragment onResume() & onPause()不会在backstack上被调用
- 如何设置基线对齐为假提高性能在线性布局?