九补丁不需要的图像绵延闪屏 [英] Unwanted stretching of nine-patch image for splash screen

查看:154
本文介绍了九补丁不需要的图像绵延闪屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个九宫格图像,使其闪屏为我的应用程序,它应该是相同的(平方)在纵向和横向方向。

我的code是简单的:

 公共无效的onCreate(捆绑冰柱){
    super.onCreate(冰柱);
    的setContentView(R.layout.splashscreen);
  //更多code这里...
}

我的资源文件是:

 <?XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目>
        <位图的android:SRC =@绘制/ launch_image/>
    < /项目>
< /层列表>

九宫图像看起来罚款,绘制9补丁程序:

但作为结果的图像被拉伸:

有什么不对?可以九宫格图像在所有使用这种方式?


解决方案

CAN九宫图像在所有使用这种方法

哦,不。不正常。

由于9修补程序,目的是要伸展。结果
一个很好的教程:<一href=\"http://radleymarx.com/blog/simple-guide-to-9-patch/\">http://radleymarx.com/blog/simple-guide-to-9-patch/

您最好使用一个正方形图片,并把它作为一个的android:SRC ),不作为背景(的android:背景)为您的ImageView的结果。
然后,你可以通过设置安卓ajust它:(? FIT_XY )scaleType 属性。

参考:<一href=\"http://developer.android.com/reference/android/widget/ImageView.ScaleType.html\">http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

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?

解决方案

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

这篇关于九补丁不需要的图像绵延闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆