我有一个全屏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
使用PNG并不是一个好主意。实际上,就性能而言,这是昂贵的。 您可以使用可绘制的XML文件,例如,Facebook的背景。
这将帮助你平滑和加速你的性能,并为标志使用。9补丁图像。
我已经搜索了最好最简单的答案来制作9-patch image。现在制作9个补丁映像是最简单的任务。
从https://romannurik.github.io/AndroidAssetStudio/index.html,您可以制作一个9补丁图像的所有分辨率- XHDPI,HDPI,MDPI,LDPI只需点击一下。
竖屏模式
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作为启动画面
**如果您正在寻找各种主要设备的屏幕细节**
访问material.io
推荐文章
- Keytool错误:java.io。IoException:错误的AVA格式
- GCM与PHP(谷歌云消息传递)
- 自定义圆圈按钮
- 我如何使用一个复合绘图而不是一个线性布局,包含一个ImageView和一个TextView
- 如何绘制一个线性布局的边界
- 如何动画添加或删除Android列表视图行
- 如何解决“丢失的PendingIntent可变性标志”在android api 30+ lint警告?
- 我怎么能修复“意外元素<查询>发现<manifest>”错误?
- Android房间-自动生成新插入行的id
- Android Studio在哪里保存ProGuard映射文件?
- 我如何从资产文件夹解析一个本地JSON文件到一个ListView?
- Android 4.4 (KitKat)上的Android Gallery为Intent返回不同的URI。ACTION_GET_CONTENT
- 移除动作栏下面的阴影
- 如何在线性布局的一侧绘制边界?
- 找到可移动SD卡的位置