2012-11-15 64 views
2

我正在尝试使用ImageButton视图使用一些简单的9patch PNG照片,但它们不能正确缩放。例如,下面是我使用的9patch PNG图像:麻烦缩放9patch图像均匀

Enter image description here

但是这是怎么秤:

Enter image description here

这是我的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> 

我是r最后不知道为什么图像的内容(锁)比左侧靠右多了,而不是均匀拉伸并将锁保持在中心。任何想法为什么发生这种情况?感谢任何人都可以提供一些帮助。

+1

你有没有检查过,你项目中的图像是否是你期望的图像?也许左侧有更多的strech区域 – zapl

回答

1

从9-patch中取出锁定图像,制作一个带有锁定的独立PNG,并用android:src来代替。按钮使用中心android:layout_gravity=center

+1

好的建议,这应该工作。谢谢!不过,我仍然很想知道为什么图像只能在一个方向上缩放而不是均匀,或者甚至可能。 – user1825535

+0

你应该接受答案 –