Android 无法均匀缩放面片图像
我正在尝试制作一些简单的9patch PNG照片,用于Android 无法均匀缩放面片图像,android,android-layout,android-widget,png,nine-patch,Android,Android Layout,Android Widget,Png,Nine Patch,我正在尝试制作一些简单的9patch PNG照片,用于ImageButton视图,但是它们没有正确缩放。例如,下面是我正在使用的9patch PNG图像: 但这是它的扩展方式: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" a
ImageButton
视图,但是它们没有正确缩放。例如,下面是我正在使用的9patch PNG图像:
但这是它的扩展方式:
<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>
这是我的按钮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>
我真的不知道为什么图像会随着内容(锁)向右移远比向左移,而不是均匀拉伸并将锁保持在中心。你知道为什么会这样吗?感谢所有人提供的帮助。从9-patch中取出锁图像,用锁制作一个单独的PNG,用android:src来定义它。使用android:layout\u gravity=center在按钮中居中,您是否检查了项目中的图像是否是您期望的图像?也许左侧有更多的拉伸区域好的建议,这应该行得通。非常感谢。然而,我仍然想知道为什么图像似乎只是在一个方向上缩放,而不是均匀缩放,或者这是可能的。