为什么我的9补丁不能正常工作?

时间:2013-12-26 03:42:50

标签: android nine-patch

我的搜索框右侧有一个带有放大镜图标的9补丁图片,

问题是,当我把它作为我的edittext的背景时,图像不适合。 (我无法上传截屏)

放大镜图标没有按预期工作,图标缩小了。有人可以帮我解决这个问题吗?

这里是我的XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListFoodActivity"
android:padding="10dp"
android:background="@drawable/bcground"
android:src="@drawable/bcground" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="100dp"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="5dp"
    android:text="Food"
    android:textSize="20sp"
    android:textStyle="bold" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="150dp"
    android:layout_height="40dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/textView1"
    android:background="@drawable/search"
    android:hint="Search"
    android:textSize="20sp"
    android:textStyle="bold" />

这里有9个补丁图片:

enter image description here

和模拟器的图像:

enter image description here

抱歉英语不好:(

2 个答案:

答案 0 :(得分:0)

问题在于9补丁本身:它是格式错误 左侧上的黑线简直是错误的(它“触及”镜头) 它应该是靠近下部的单个像素,因此它的延长不会接触镜头。

这就是它

enter image description here

请注意,镜头将右上对齐 如果你想要居中,你必须在左上边框附近添加另一个黑色像素(但你必须更换上镜头框附近的一些像素)。

也不是你不需要水平部分那么宽,你可以使它更窄,以节省最终的补丁尺寸。

答案 1 :(得分:-1)

使用9patch创建照片后,您可以将文件扩展名为XX.9.png的图像文件。 例如,search.9.png在drawable文件夹中你应该在xml中使用“android:background = @ drawable / search”。

相关问题