我已經在LinearLayout中包裝了EditText控件旁邊的Button。一切似乎都很好,除了Button明顯高於EditText,我希望它的高度相同。 @ drawable/main_edittext和@ drawable/main_edittext_button的高度是相同的,但即使沒有背景設置,高度也是不同的。在應用程序清單文件中,應用程序主題只設置爲windowNoTitle = true。EditText和Button高度問題
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/main_background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/edit_message"
style="@style/MainEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message"
android:singleLine="true" />
<Button
android:id="@+id/edit_message_button"
style="@style/MainSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="@string/button_send" />
</LinearLayout>
<style name="MainEditText">
<item name="android:background">@drawable/main_edittext</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#262626</item>
</style>
<style name="MainSearchButton">
<item name="android:background">@drawable/main_edittext_button</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#ff5500</item>
</style>
+ main_edittext.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/edit_text">
</item>
<item
android:state_enabled="true"
android:state_focused="true"
android:drawable="@drawable/edit_text">
</item>
<item android:state_enabled="true"
android:drawable="@drawable/edit_text">
</item>
</selector>
-main_edittext.xml
+ main_edittext_button.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/edit_text_button">
</item>
<item
android:state_focused="true"
android:drawable="@drawable/edit_text_button">
</item>
<item android:drawable="@drawable/edit_text_button" />
</selector>
-main_edittext_button.xml
它們具有依賴於Android平臺版本的內在填充。請參閱源代碼進行驗證:https://github.com/android/platform_frameworks_base/tree/master/core/res/res/values – Blundell 2012-07-10 20:18:42