我有一个全屏PNG,我想显示在飞溅。只有一个错误,我也不知道 每个可绘制文件夹(ldpi、mdpi、hdpi和xhdpi)的大小。我的应用程序应该在所有的手机和平板电脑上运行良好和美观。我应该创建什么大小(以像素为单位),以便在所有屏幕上显示良好的飞溅?
当前回答
我已经搜索了最好最简单的答案来制作9-patch image。现在制作9个补丁映像是最简单的任务。
从https://romannurik.github.io/AndroidAssetStudio/index.html,您可以制作一个9补丁图像的所有分辨率- XHDPI,HDPI,MDPI,LDPI只需点击一下。
其他回答
**如果您正在寻找各种主要设备的屏幕细节**
访问material.io
使用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
根据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)
前段时间我创建了一个支持维度的excel文件 希望这对某些人有所帮助
老实说,我失去了想法,但它指的是另一个屏幕功能的大小(不仅仅是密度) https://developer.android.com/guide/practices/screens_support.html 如果有错误,请告诉我
Link1: dimensions.xlsx
Link2: dimensions.xlsx
推荐文章
- 为什么“System.out。”println“工作在Android?
- WebView显示err_cleartext_not_allowed尽管站点是HTTPS
- Android M权限:对shouldShowRequestPermissionRationale()函数的使用感到困惑
- 为什么构建类型与产品风味不同?
- 我如何在一个片段中访问getSupportFragmentManager() ?
- 调试在哪里。Android Studio中的密钥存储库
- 从资产中读取文件
- 在不活动的地方调用getLayoutInflater()
- 设置Android布局元素的背景颜色
- 错误:'keytool'不能被识别为内部或外部命令、可操作程序或批处理文件
- 在应用程序本身中更改Locale
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置