【问题标题】:Constraint layout as a parent, my Linear layout doesn't touch the bottom, why not?约束布局作为父级,我的Linear布局不触底,为什么呢?
【发布时间】:2018-08-06 11:39:20
【问题描述】:

我的 XML 模式是:

约束

-线性

-线性

-文本视图

-线性[不接触背景]

线性布局内的三个按钮:

我的 XML 代码[结尾部分]:

    <LinearLayout 
    android:id="@+id/linear_controlBtn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="@android:color/background_light"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/button_start_pause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:fontFamily="@font/roboto"
        android:text="start"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="24sp" />

    <Button
        android:id="@+id/button_reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:fontFamily="@font/roboto"
        android:text="reset"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="24sp"
        android:visibility="invisible"
        tools:visibility="visible" />

    <Button
        android:id="@+id/button_set"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:fontFamily="@font/roboto"
        android:text="Set"
        android:textColor="@android:color/holo_green_dark"
        android:textSize="24sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>

这看起来像一个愚蠢的错误,但我不知道错误在哪里。

【问题讨论】:

  • 向我们展示您的完整布局
  • 请发布完整的xml代码
  • 您应该向我们展示所有布局代码,但看起来您的LinearLayout 有一些marginBottom

标签: android android-linearlayout


【解决方案1】:

像这样用于边距,设置右侧、左侧和顶部边距,不要设置底部边距,如果设置了底部边距,则移除并勾选

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginLeft="5dp">

【讨论】:

    【解决方案2】:

    请删除约束布局和线性布局的底部边距或边距。它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      • 1970-01-01
      相关资源
      最近更新 更多