在约束布局中按钮没有完全粘在屏幕底部
Button doesn't fully stick to bottom of screen in constraint layout
我约束了一个按钮到屏幕底部,可惜屏幕底部边框和按钮底部边框之间有一个小缝隙:
我的XML:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/navigationTabs"
android:layout_width="match_parent"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:tabMinWidth="100dp"
app:tabRippleColor="@null"
/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="BUTTON"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"/>
<LinearLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigationTabs" />
</androidx.constraintlayout.widget.ConstraintLayout>
造成这种差距的原因是什么?我怎样才能摆脱它?
默认背景按钮周围的阴影。指定你自己的背景,差距就会消失。
例如:
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#A4ABA4"
android:text="BUTTON"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"/>
将此代码添加到 <androidx.constraintlayout.widget.ConstraintLayout ...>
和 <button ...>
:
android:layout_margin="0dp"
android:padding="0dp"
将此代码添加到 <com.google.android.material.tabs.TabLayout ...>
和 <LinearLayout ...>
和 <button ...>
:
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
将此代码添加到 <button ...>
:
android:background="#c0c0c0"
我约束了一个按钮到屏幕底部,可惜屏幕底部边框和按钮底部边框之间有一个小缝隙:
我的XML:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/navigationTabs"
android:layout_width="match_parent"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:tabMinWidth="100dp"
app:tabRippleColor="@null"
/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="BUTTON"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"/>
<LinearLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigationTabs" />
</androidx.constraintlayout.widget.ConstraintLayout>
造成这种差距的原因是什么?我怎样才能摆脱它?
默认背景按钮周围的阴影。指定你自己的背景,差距就会消失。 例如:
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#A4ABA4"
android:text="BUTTON"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"/>
将此代码添加到 <androidx.constraintlayout.widget.ConstraintLayout ...>
和 <button ...>
:
android:layout_margin="0dp"
android:padding="0dp"
将此代码添加到 <com.google.android.material.tabs.TabLayout ...>
和 <LinearLayout ...>
和 <button ...>
:
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
将此代码添加到 <button ...>
:
android:background="#c0c0c0"