这是正在发生的事情:按钮调整大小上> 2.3.6
这是源图像:
这是XML布局的一部分:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_headers"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="@+id/etNewItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:completionThreshold="2"
android:dropDownHeight="wrap_content"
android:dropDownWidth="wrap_content"
android:hint="@string/et_newitemhint"
android:inputType="text|textCapSentences"
android:layout_centerVertical="true"
style="@style/DialogEditText"
android:layout_marginRight="10dp"
android:singleLine="true" />
<Button
android:id="@+id/btnAddNew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/btn_add"
android:layout_centerVertical="true" />
</RelativeLayout>
这是按钮的选择器xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true"
android:drawable="@drawable/btn_add_pressed"/>
<item android:state_pressed="true"
android:drawable="@drawable/btn_add_pressed"/>
<item android:drawable="@drawable/btn_add_normal"/>
</selector>
为什么此按钮在4.x.x中水平调整大小?源图形确实使用了9个补丁,但它做了完全相同的事情,所以我将其更改为正常的png,但没有任何结果。
奇怪的是,这是唯一显示此行为的图形。我把它放在某个地方的一个操作栏上:同样的事情;我也在对话中说过:同样的事情。
我的2.2.2和2.3.6测试设备显示按钮应该是,但我的任何4.x.x测试设备显示拉长的按钮。
只是在黑暗中刺,但你有没有尝试过使用'ImageButton'而不是'Button',并通过'android:src =“..”'而不是'android:background =“设置drawable。 “'?我想知道是否使用背景属性不允许按钮正确测量其大小,因此,奇怪的结果, –
感谢您的建议@AlexMDC,您的解决方案可能已经工作,但我直接从androbat的代码,它做了。 – DaveSav