Unwanted stretching of nine-patch image for splash screen

冷暖自知 提交于 2019-12-13 08:45:05

问题


I want to use a nine-patch image to make a splash screen for my application, which should look the same (square) in both portrait and landscape orientation.

My code is simple:

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

My resource file is:

<?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>

Nine-patch image looks fine in Draw 9-patch utility:

But as the result the image is stretched:

What's wrong? Can nine-patch images be used this way at all?


回答1:


Can nine-patch image be used this way at all? Well, no. Not properly.

Because 9 patches are meant to be stretchable.
A nice tutorial: http://radleymarx.com/blog/simple-guide-to-9-patch/

You'd better use a square image and use it as a source (android:src), not as a background (android:background) for your ImageView.
Then you can ajust it by setting the android:scaleType attribute (FIT_XY?).

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



来源:https://stackoverflow.com/questions/29752555/unwanted-stretching-of-nine-patch-image-for-splash-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!