Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 简单视图不能与底部对齐以约束视图_Android_Android Constraintlayout - Fatal编程技术网

Android 简单视图不能与底部对齐以约束视图

Android 简单视图不能与底部对齐以约束视图,android,android-constraintlayout,Android,Android Constraintlayout,[更新1] 布局标记用于数据绑定。我尝试删除布局并将ConstraintLayout作为根容器,问题仍然存在,谢谢 我只想让视图在ContrintLayout的底部对齐,但我总是在视图和底部之间有一个边距/间隙 代码如下: <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <

[更新1]

布局
标记用于数据绑定。我尝试删除
布局
并将ConstraintLayout作为根容器,问题仍然存在,谢谢

我只想让视图在ContrintLayout的底部对齐,但我总是在视图和底部之间有一个边距/间隙

代码如下:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="0dp">

        <Button
            android:text="Button"
            android:id="@+id/button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp">

    <Button
        android:text="Button"
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</FrameLayout>

设备上的外观是

但是,如果我用FrameLayout替换ContrainLayout,则所有内容都是文件

代码如下:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="0dp">

        <Button
            android:text="Button"
            android:id="@+id/button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp">

    <Button
        android:text="Button"
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</FrameLayout>

以及它的外观(按钮和家长底部之间没有额外的空间):


我在这个问题上挣扎了至少7~8个小时,仍然不知道发生了什么。有人有什么想法吗?谢谢。

我认为您不需要在xml中使用
layout
标记

将其放在xml文件中:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <Button
            android:text="Button"
            android:id="@+id/button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

尝试以下代码:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <Button
            android:id="@+id/button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Button"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

经过一些实验,我从ConstraintLayout库中找到了根本原因

对于1.1.3版,一切正常。
实现“androidx.constraintlayout:constraintlayout:1.1.3”

然而,当我将版本升级到2.0.0-beta2时,发生了这种奇怪的行为。
实现“androidx.constraintlayout:constraintlayout:2.0.0-beta2”


我应该只使用稳定版本,谢谢大家。

您真的需要父布局(甚至没有结束标记)吗?最好将xmlns:android和xmlns:app直接放到ConstraintLayout中。顺便说一句,这看起来是一款非常酷的设备那是什么东西?它在仿真器上工作吗?使用布局检查器尝试找出发生了什么。在Android Studio中,它是工具->布局检查器,然后选择您的应用程序。@qwerty我在项目中使用数据绑定,这就是为什么您会看到父应用程序。该设备具有物理按钮和红外扫描仪。它在模拟器上运行良好。如果应用程序必须仅在此设备上运行,您可以尝试使用负边距/填充。不幸的是,此应用程序在许多不同的设备上运行,一些设备具有物理按钮,其他设备则没有。无论是否有
布局
标记作为父项(我在本项目中使用数据绑定),问题仍然存在。仅从xml文件中删除
标记不会产生任何效果。