Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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_Xml_Android Layout_Android Constraintlayout - Fatal编程技术网

Android 如何将视图约束到另一个布局文件中的视图?

Android 如何将视图约束到另一个布局文件中的视图?,android,xml,android-layout,android-constraintlayout,Android,Xml,Android Layout,Android Constraintlayout,我的应用程序使用在主活动布局中定义的表格布局。然后,每个选项卡都有一个单独的布局文件,用于放置该选项卡的所有视图 在选项卡布局文件中,我希望将视图约束到选项卡的底部边缘。我不知道该怎么做,因为tabLayout是在另一个布局文件中定义的,并且它没有固定的高度(我真的不希望这样),所以我不能在tab布局文件中使用相同的尺寸 我已经看到有一个标签,你可以使用它从其他版面中拉入内容,但这感觉不对,我不需要在标签中复制整个版面,我只需要知道它的高度 这是我的主要活动布局,其中包含表格布局 <?xm

我的应用程序使用在主活动布局中定义的表格布局。然后,每个选项卡都有一个单独的布局文件,用于放置该选项卡的所有视图

在选项卡布局文件中,我希望将视图约束到选项卡的底部边缘。我不知道该怎么做,因为tabLayout是在另一个布局文件中定义的,并且它没有固定的高度(我真的不希望这样),所以我不能在tab布局文件中使用相同的尺寸

我已经看到有一个标签,你可以使用它从其他版面中拉入内容,但这感觉不对,我不需要在标签中复制整个版面,我只需要知道它的高度

这是我的主要活动布局,其中包含表格布局

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/backgroundColour"
    tools:context=".MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme"
        app:layout_constraintTop_toTopOf="parent"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"     
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <android.support.design.widget.TabItem
            android:id="@+id/CostTab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cost" />

        <android.support.design.widget.TabItem
            android:id="@+id/costTab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/distance" />

    </android.support.design.widget.TabLayout>


    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/tabMenu"
        />

</android.support.constraint.ConstraintLayout>


您应该使用每个表格布局的片段填充ViewPager适配器,或者使用普通视图作为适配器项。您可以在这里的开发者指南中找到更多信息:

我不确定我是否遵守了。每个选项卡都有片段,每个片段都有相应的布局文件。选项卡功能运行良好,只是在我的每个片段布局文件中,我必须大致猜测选项卡的结束位置和“可用空间”的开始位置。“可用空间”从片段布局文件的顶部开始,因此如果要将视图约束到选项卡的底部边缘,您只需要将其约束到fragment布局文件的顶部。如果您需要知道选项卡中布局的高度,只需使用此答案中描述的方法: