Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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 Can';t使包含的视图与布局中的父底部对齐_Android_Android Layout_Android Relativelayout - Fatal编程技术网

Android Can';t使包含的视图与布局中的父底部对齐

Android Can';t使包含的视图与布局中的父底部对齐,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,我试图在android中做一个简单的布局,其中包含另一个文件,它是一个底部导航,由三个按钮组成 我无法使包含的文件在底部对齐。以下是我的布局xml(文本视图显示为与父级底部对齐,但包含的文件不对齐): 包含的文件: <merge xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.constraint.ConstraintLayout xmlns:android="http

我试图在android中做一个简单的布局,其中包含另一个文件,它是一个底部导航,由三个按钮组成

我无法使包含的文件在底部对齐。以下是我的布局xml(文本视图显示为与父级底部对齐,但包含的文件不对齐):


包含的文件:

<merge xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/task_base_buttons"
android:layout_width="match_parent"
android:layout_height="66dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/btnTaskBack"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_back"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

    <Button
        android:id="@+id/btnTaskContinue"
        style="@style/NeutrifProText.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_weight="0.6"
        android:background="@drawable/rounded_rect_color_primary"
        android:text="@string/action_continue"
        android:textColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btnTaskSkip"
        app:layout_constraintStart_toEndOf="@+id/btnTaskBack" />

    <Button
        android:id="@+id/btnTaskSkip"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_skip"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

 </android.support.constraint.ConstraintLayout>
 </merge>

知道为什么吗?顺便说一句,这个包含的文件显示在片段的底部

编辑:我正在包括片段的布局,布局确实出现在底部

<android.support.constraint.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:id="@+id/task_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rangerhealth.rangerprovider.view.fragment.BaseTaskFragment"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">

<!-- TODO: Update blank fragment layout -->

<TextView
    android:id="@+id/task_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="50dp"
    android:gravity="center"
    android:textColor="@color/black"
    android:textSize="@dimen/title_font_size"
    tools:text="Title"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/task_subtitle"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/task_title"
    android:layout_centerHorizontal="true"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="17dp"
    android:gravity="center"
    tools:text="Subtitle"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/task_title" />

<TextView
    android:id="@+id/task_description"
    android:layout_width="match_parent"
    android:layout_height="21dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:gravity="center_horizontal"
    tools:text="Description"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/task_subtitle" />


<include layout="@layout/bottom_navigation"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    />

<RelativeLayout
    android:id="@+id/task_placeholder"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/task_description"
    app:layout_constraintBottom_toTopOf="@id/task_base_buttons"
    >

</RelativeLayout>
</android.support.constraint.ConstraintLayout>

在布局中,包含的布局与父级底部和下方对齐
patientDOBBlock
。这两个指令相互冲突。我假设您希望底部导航和文本视图都与父底部对齐并重叠

在包含的布局中,删除以下行:

android:layout_below="@+id/patientDOBBlock"
这将保留以下布局:

<RelativeLayout 
    android:id="@+id/activity_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <TextView
        android:id="@+id/patientDOBBlock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        tools:text="Test Navigation Text" />

    <include
        android:id="@+id/navigation"
        layout="@layout/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="66dp"
        android:layout_alignParentBottom="true"
        app:layout_constraintBottom_toBottomOf="parent" />
</RelativeLayout>
结果如下:


尽管这不会造成任何影响,但在
ConstraintLayout
中指定的约束将无效,除非父对象也是
ConstraintLayout
,因此可以删除它们。

使用以下内容更改XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">


    <TextView
        android:id="@+id/patientDOBBlock"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/navigation"
        android:gravity="center"
        tools:text="Test Navigation Text" />

    <include
        android:id="@+id/navigation"
        layout="@layout/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="66dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

bottom_navigation.xml

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/task_base_buttons"
android:layout_width="match_parent"
android:layout_height="66dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/btnTaskBack"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_back"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

    <Button
        android:id="@+id/btnTaskContinue"
        style="@style/NeutrifProText.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_weight="0.6"
        android:background="@drawable/rounded_rect_color_primary"
        android:text="@string/action_continue"
        android:textColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btnTaskSkip"
        app:layout_constraintStart_toEndOf="@+id/btnTaskBack" />

    <Button
        android:id="@+id/btnTaskSkip"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_skip"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

 </android.support.constraint.ConstraintLayout>

事实上,我不得不添加一个线性布局,然后一切正常:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">


<TextView
    android:id="@+id/patientDOBBlock"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/navigation"
    android:gravity="center"
    tools:text="Test Navigation Text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/navigation">

<include
    android:id="@+id/constraintLayoutNavigation"
    layout="@layout/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="66dp"
    android:layout_alignParentBottom="true" />
</LinearLayout>

</RelativeLayout>


这应该能很好地工作

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/task_base_buttons"
android:layout_width="match_parent"
android:layout_height="66dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/btnTaskBack"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_back"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

    <Button
        android:id="@+id/btnTaskContinue"
        style="@style/NeutrifProText.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_weight="0.6"
        android:background="@drawable/rounded_rect_color_primary"
        android:text="@string/action_continue"
        android:textColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btnTaskSkip"
        app:layout_constraintStart_toEndOf="@+id/btnTaskBack" />

    <Button
        android:id="@+id/btnTaskSkip"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_skip"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

 </android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">


<TextView
    android:id="@+id/patientDOBBlock"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/navigation"
    android:gravity="center"
    tools:text="Test Navigation Text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/navigation">

<include
    android:id="@+id/constraintLayoutNavigation"
    layout="@layout/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="66dp"
    android:layout_alignParentBottom="true" />
</LinearLayout>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/patientDOBBlock"
tools:text="Test Navigation Text"
android:layout_above = "@+id/navigation"/>

<include
android:id="@id/navigation"
android:layout_alignParentBottom = "true"
layout="@layout/bottom_navigation"
android:layout_height="66dp"
android:layout_width="match_parent"
/>
</RelativeLayout>