It’s a little bit to the right.
我认为保证金正在引起这些.根据我的经验,它不仅影响按钮.保证金也在拧紧TextInputEditText.
下面是一个工作代码,但请注意按钮上的android:layout_width =“match_parent”.任何时候我在编辑器中单击它,它将更改为android:layout_width =“0dp”,并破坏按钮对齐.
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:id="@+id/button_survey"
android:layout_width="match_parent"
android:layout_height="52dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="@+id/activity_main"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
app:layout_constraintTop_toTopOf="@+id/activity_main"
tools:text="@string/main_activity_btn_survey"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp" />
受Hobo joe解决方案的启发,下面是我喜欢的方式.他的解决方案正在解决,但仍需要使用填充来创建间距.如果使用了margin,则按钮文本的对齐方式将略微向右移动.所以我在LinearLayout(或ConstraintLayout)上使用填充而不是按钮上的边距.
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintTop_toTopOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
app:layout_constraintBottom_toBottomOf="@+id/activity_main"
android:padding="16dp">
android:text="Button"
android:layout_width="match_parent"
android:layout_height="52dp"
android:id="@+id/button_survey"
android:layout_weight="1"
tools:text="@string/main_activity_btn_survey"
/>