飞溅屏幕上九个补丁图像的不需要的拉伸

时间:2015-04-20 15:49:59

标签: android nine-patch

我想使用九个补丁图像为我的应用程序制作一个启动画面,它在纵向和横向方向看起来应该是相同的(正方形)。

我的代码很简单:

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.splashscreen);
  // more code here...
}

我的资源文件是:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap android:src="@drawable/launch_image" />
    </item>
</layer-list>

在补丁9补丁实用程序中,九补丁图像看起来很好: enter image description here

但结果是图像被拉伸: enter image description here

出了什么问题?九个补丁图像可以这样使用吗?

1 个答案:

答案 0 :(得分:5)

Can nine-patch image be used this way at all?嗯,不。不正确。

因为9个补丁意味着可伸展 一个很好的教程:http://radleymarx.com/blog/simple-guide-to-9-patch/

您最好使用方形图像并将其用作sourceandroid:src),而不是用作ImageView的背景(android:background)。
然后,您可以通过设置android:scaleType属性(FIT_XY?)来调整它。

参考:http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

相关问题