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

dek*_*eko -1 android nine-patch

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

我的代码很简单:

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

我的资源文件是:

<?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>
Run Code Online (Sandbox Code Playgroud)

在Draw 9-patch实用程序中,九个补丁图像看起来很好: 在此输入图像描述

但结果是图像被拉伸: 在此输入图像描述

怎么了?九个补丁图像可以这样使用吗?

Fan*_*mas 5

Can nine-patch image be used this way at all?好吧,不.不正确.

因为9个贴片是可伸缩的.
一个很好的教程:http://radleymarx.com/blog/simple-guide-to-9-patch/

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

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

  • 我接受“九补丁图像不能这样使用”的答案。 (2认同)