【问题标题】:Trouble scaling 9patch images evenly无法均匀缩放 9patch 图像
【发布时间】:2012-11-03 16:14:33
【问题描述】:

我正在尝试制作一些简单的 9patch PNG 照片以用于ImageButton 视图,但是它们的缩放比例不正确。例如,这是我正在使用的 9patch PNG 图片:

但它是这样扩展的:

这是我的按钮 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"  >

<ImageButton
    android:id="@+id/add_challenge1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add1" />

<ImageButton
    android:id="@+id/add_challenge2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add2" />

<ImageButton
    android:id="@+id/add_challenge3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add3" />

<ImageButton
    android:id="@+id/add_challenge4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add4" />

<ImageButton
    android:id="@+id/add_challenge5"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add5" />                          
</LinearLayout> 

我真的不确定为什么图像会随着内容(锁)的缩放而向右比向左更远,而不是均匀拉伸并将锁保持在中心。关于为什么会发生这种情况的任何想法?非常感谢任何人都可以提供一些帮助。

【问题讨论】:

  • 您是否检查过,您项目中的图像实际上是您期望的那个图像?也许左侧有更多的拉伸区域

标签: android android-layout android-widget png nine-patch


【解决方案1】:

将锁定图像从 9-patch 中取出,制作一个单独的带锁定的 PNG,并改为使用 android:src 定义它。要居中按钮使用android:layout_gravity=center

【讨论】:

  • 好建议,这应该可行。谢谢!但是我仍然很想知道为什么图像似乎只在一个方向而不是均匀地缩放,或者这是否可能。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-22
  • 1970-01-01
  • 2019-09-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多