我的应用程序使用在main_activity布局中定义的tabLayout。然后,我每个选项卡都有一个单独的布局文件,用于放置该选项卡的所有视图。
在标签页布局文件中,我想将视图限制在标签页的底部边缘。我不知道如何执行此操作,因为tabLayout是在另一个布局文件中定义的,并且它没有固定的高度(而且我真的不希望如此),所以我不能只使用相同的尺寸在标签布局文件中。
我已经看到有一个标签,您可以使用该标签从其他布局中提取内容,但这感觉不对,我不需要在标签中复制整个布局,我基本上只需要知道它的高度。
这是我的main_activity布局,其中包含tabLayout。
<?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>