为什么9补丁图形的大小正确的仿真器,但没有一个电话? [英] Why do 9-patch graphics size correctly in the emulator but not on a phone?
问题描述
我有一个RelativeLayout的,有一个9贴片的背景图像。该图像是一个简单的语音泡了完全居中箭头在底部中间。
的RelativeLayout的膨胀,并放置在图形页面。使用仿真器,该语音气泡可以容易地指着一位置和将扩大到它的内容(文字,图像,或两者)。当我在手机上运行我的应用程序然而,9修补程序不舒展正常。的箭头对于语音泡沫将通过一个非常明显的量向左偏移。
我主要测试在Nexus S的,而且三星的Captivate和Nexus One的。针对SDK 7测试模拟器的SDK 7+。只有硬件设备似乎有这个问题。
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / BubbleLayout
机器人:背景=@可绘制/泡沫
机器人:layout_width =WRAP_CONTENT
机器人:重力=center_horizontal>
< TextView的Android版本:layout_height =WRAP_CONTENT
机器人:ID =@ + ID /日期
机器人:layout_width =WRAP_CONTENT
机器人:=了maxWidth196dp>< / TextView的>
< TextView的Android版本:layout_below =@ + ID /日期
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:=了maxWidth196dp
机器人:ID =@ + ID /摘要>< / TextView的>
< / RelativeLayout的>
请确保你有一个MDPI和华电国际的版本,如果你测试在不同的密度。如果你把你的9patch在RES /绘制/例如,它会被当作一个MDPI资产和华电国际设备(歌Nexus S)自动扩大规模。因为它是一个自动的过程,其结果不能保证。
I have a RelativeLayout that has a 9-patch background image. The image is a simple speech bubble with a perfectly centered "arrow" at the bottom middle.
The RelativeLayout is inflated and placed on a MapView. Using the emulator, the speech bubble can be easily pointed to a location and will expand to its contents (text, an image, or both). When I run my app on a phone however, the 9-patch doesn't stretch properly. The "arrow" for the speech bubble will be offset to the left by a very noticeable amount.
I primarily test on a Nexus S, but also a Samsung Captivate and Nexus One. Targeting SDK 7. Tested emulators for SDK 7+. Only hardware devices seem to have this problem.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:id="@+id/BubbleLayout"
android:background="@drawable/bubble"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<TextView android:layout_height="wrap_content"
android:id="@+id/date"
android:layout_width="wrap_content"
android:maxWidth="196dp"></TextView>
<TextView android:layout_below="@+id/date"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:maxWidth="196dp"
android:id="@+id/summary"></TextView>
</RelativeLayout>
Make sure you have an mdpi and an hdpi version if you test on different densities. If you put your 9patch in res/drawable/ for instance, it will be treated as an mdpi asset and scaled up automatically on hdpi devices (Nexus S). Because it's an automatic process, the results are not guaranteed.
这篇关于为什么9补丁图形的大小正确的仿真器,但没有一个电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!