在约束布局中,按钮没有完全粘在屏幕底部

时间:2020-02-09 05:37:19

标签: android android-constraintlayout android-button

我将按钮限制在屏幕的底部,但不幸的是,屏幕的底部边框和臀部的底部边框之间有一个小缝隙:

enter image description here

我的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>

是什么原因造成这种差距?而我该如何摆脱呢?

1 个答案:

答案 0 :(得分:2)

这是默认背景按钮周围的阴影。指定您自己的背景,差距将消失。 例如:

<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"/>