我無法將默認材質按鈕與UI的其他元素對齊。事實上,我已經看過了Android的源代碼以及按鈕的背景包含插圖點擊時能夠繪製陰影和處理按鈕的海拔:如何將材質按鈕與其他UI元素對齊
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_button_inset_horizontal_material"
android:insetTop="@dimen/abc_button_inset_vertical_material"
android:insetRight="@dimen/abc_button_inset_horizontal_material"
android:insetBottom="@dimen/abc_button_inset_vertical_material">
<shape android:shape="rectangle">
<corners android:radius="@dimen/abc_control_corner_material" />
<solid android:color="@android:color/white" />
<padding android:left="@dimen/abc_button_padding_horizontal_material"
android:top="@dimen/abc_button_padding_vertical_material"
android:right="@dimen/abc_button_padding_horizontal_material"
android:bottom="@dimen/abc_button_padding_vertical_material" />
</shape>
</inset>
所以,我有非常基本的以下佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#123456"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test button alignment"
/>
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#123456"
/>
</LinearLayout>
正如你所看到的,按鈕的左邊緣不與其他視圖的左邊緣對齊。
所以我的問題是,有沒有辦法來擺脫這些插圖的無鬆動默認的Android按鍵開箱處理有UI的影子/仰角以及對齊?
謝謝!
這應該使用[光學佈局界限(https://developer.android.com/about/versions/android-4.3.html#OpticalBounds)是可能的,但我有麻煩這個專門處理材料按鈕。 –