9补丁内容区错误
9Patch content area error
我的内容区域似乎与 9patch 文件所说的不符
这是我的 9patch 文件。
这是其中包含一个项目的图片,但是文本被过早地截断了,它应该是 "Varenr." 我不知道不明白为什么有这么大的白space而不是文字??
这里是微调器的 xml 布局:
<Spinner
android:id="@+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="@string/sort" />
和微调器项目
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:gravity="center"
android:singleLine="true" />
在此先感谢您的帮助。
为了结束,有问题的 9patch:
编辑:
微调器所在的整行:
<LinearLayout
android:id="@+id/headerLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@color/transparent"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/sortAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="false"
android:textColor="@color/solid_red"
android:textSize="15dp" />
<TextView
android:id="@+id/sortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Produkter"
android:singleLine="true"
android:textColor="@color/solid_red"
android:textSize="15dp" />
</LinearLayout>
<Button
android:id="@+id/filterBtn"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:background="@drawable/button_background_red"
android:clickable="true"
android:singleLine="true"
android:onClick="setFilterList"
android:text="Filtrér"
android:textColor="@color/solid_white"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="@+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:paddingRight="30dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="@string/sort" />
</LinearLayout>
现在,这就是我重新制作它的方式:
结果如下:
确保扩展名是 .9.png
[编辑]
这是应用于 TextView 时的结果:
屏幕是旧的 ldpi 设备 (240x320 @120 dpi)
我是这样应用的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stripes_vert_4"
>
<!-- ... -->
<TextView
android:id="@+id/txtTitle3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentBottom="true"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:text="Lorem ipsum dolor sit amet"
android:background="@drawable/spinner_drawable"
/>
</RelativeLayout>
[编辑 2]
根据 OP 要求,我将 TextView 切换为 Spinner:
结果:
通过使用此代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stripes_vert_4"
>
<!-- ... -->
<Spinner
android:id="@+id/spnElements"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:entries="@array/prefs_search_modes"
android:layout_alignParentBottom="true"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:background="@drawable/spinner_drawable"
/>
</RelativeLayout>
这意味着您的 value
文件夹中有一个 arrays.xml
文件。
我的是:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Settings -->
<!-- Word search mode -->
<string-array name="prefs_search_modes">
<item>*b* (Contains "b")</item>
<item>Ab* (Starts with "Ab")</item>
<item>*bc (Ends in "bc")</item>
<item>Abc (Exact match)</item>
</string-array>
</resources>
[EDIT3]
在最后的评论中,OP 要求(75% 白色 space + 微调器剩余的宽度)是这样的:
你确定吗?
运行 屏幕分辨率低 (ldpi)。
但在它旁边,在图形编辑器中你可以看到另一个设备 (HTC Desire Bravo) 屏幕,它是 hdpi.
它显示相同的 "issue":1/4 screen width
。
因此,9 png 背景(包含文本)的可拉伸部分被挤压掉,只有不可挤压的部分(箭头)保留。
[EDIT4]
玩过 9 补丁大小后,我可以让部分文本变得可见:
所以,看来您必须尝试较小的尺寸,直到获得可接受的结果。
[EDIT5]
我忘记添加新的 Spinner 9 补丁(已调整大小)。
这是:
缩放时,注意外边框:它必须完全透明并且标记必须全黑.
我的内容区域似乎与 9patch 文件所说的不符
这是我的 9patch 文件。
这是其中包含一个项目的图片,但是文本被过早地截断了,它应该是 "Varenr." 我不知道不明白为什么有这么大的白space而不是文字??
这里是微调器的 xml 布局:
<Spinner
android:id="@+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="@string/sort" />
和微调器项目
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:gravity="center"
android:singleLine="true" />
在此先感谢您的帮助。
为了结束,有问题的 9patch:
编辑: 微调器所在的整行:
<LinearLayout
android:id="@+id/headerLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@color/transparent"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/sortAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="false"
android:textColor="@color/solid_red"
android:textSize="15dp" />
<TextView
android:id="@+id/sortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Produkter"
android:singleLine="true"
android:textColor="@color/solid_red"
android:textSize="15dp" />
</LinearLayout>
<Button
android:id="@+id/filterBtn"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:background="@drawable/button_background_red"
android:clickable="true"
android:singleLine="true"
android:onClick="setFilterList"
android:text="Filtrér"
android:textColor="@color/solid_white"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="@+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:paddingRight="30dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="@string/sort" />
</LinearLayout>
现在,这就是我重新制作它的方式:
结果如下:
确保扩展名是 .9.png
[编辑]
这是应用于 TextView 时的结果:
屏幕是旧的 ldpi 设备 (240x320 @120 dpi)
我是这样应用的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stripes_vert_4"
>
<!-- ... -->
<TextView
android:id="@+id/txtTitle3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentBottom="true"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:text="Lorem ipsum dolor sit amet"
android:background="@drawable/spinner_drawable"
/>
</RelativeLayout>
[编辑 2]
根据 OP 要求,我将 TextView 切换为 Spinner:
结果:
通过使用此代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stripes_vert_4"
>
<!-- ... -->
<Spinner
android:id="@+id/spnElements"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:entries="@array/prefs_search_modes"
android:layout_alignParentBottom="true"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:background="@drawable/spinner_drawable"
/>
</RelativeLayout>
这意味着您的 value
文件夹中有一个 arrays.xml
文件。
我的是:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Settings -->
<!-- Word search mode -->
<string-array name="prefs_search_modes">
<item>*b* (Contains "b")</item>
<item>Ab* (Starts with "Ab")</item>
<item>*bc (Ends in "bc")</item>
<item>Abc (Exact match)</item>
</string-array>
</resources>
[EDIT3]
在最后的评论中,OP 要求(75% 白色 space + 微调器剩余的宽度)是这样的:
你确定吗?
运行 屏幕分辨率低 (ldpi)。
但在它旁边,在图形编辑器中你可以看到另一个设备 (HTC Desire Bravo) 屏幕,它是 hdpi.
它显示相同的 "issue":1/4 screen width
。
因此,9 png 背景(包含文本)的可拉伸部分被挤压掉,只有不可挤压的部分(箭头)保留。
[EDIT4]
玩过 9 补丁大小后,我可以让部分文本变得可见:
所以,看来您必须尝试较小的尺寸,直到获得可接受的结果。
[EDIT5]
我忘记添加新的 Spinner 9 补丁(已调整大小)。
这是:
缩放时,注意外边框:它必须完全透明并且标记必须全黑.