【问题标题】:Why do 9-patch graphics size correctly in the emulator but not on a phone?为什么 9-patch 图形大小在模拟器中正确,但在手机上却不行?
【发布时间】:2011-07-03 01:32:27
【问题描述】:

我有一个具有 9-patch 背景图像的 RelativeLayout。该图像是一个简单的语音气泡,底部中间有一个完全居中的“箭头”。

RelativeLayout 被膨胀并放置在 MapView 上。使用模拟器,语音气泡可以很容易地指向一个位置,并将扩展到其内容(文本、图像或两者)。但是,当我在手机上运行我的应用程序时,9-patch 无法正确拉伸。对话气泡的“箭头”将向左偏移一个非常明显的量。

我主要在 Nexus S 上进行测试,但也在三星 Captivate 和 Nexus One 上进行测试。以 SDK 7 为目标。针对 SDK 7+ 的经过测试的模拟器。似乎只有硬件设备有这个问题。

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

【问题讨论】:

    标签: android android-layout android-mapview layoutparams


    【解决方案1】:

    如果您在不同的密度上进行测试,请确保您拥有 mdpi 和 hdpi 版本。例如,如果您将 9patch 放在 res/drawable/ 中,它将被视为 mdpi 资产并在 hdpi 设备 (Nexus S) 上自动放大。因为它是一个自动过程,所以不能保证结果。

    【讨论】:

    • 谢谢!我现在已经得到了所有需要的图形,而且工作正常。我还设法通过使用具有奇数宽度的 png 并在我的图形上使用一些间距使其均匀缩放来更早地“解决”这个问题。不是一种可以遵循的方法,但认为值得一提。
    猜你喜欢
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2011-11-16
    • 2017-09-13
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    相关资源
    最近更新 更多