如何在ConstraintLayout中设置视图的高度匹配父对象? [英] How to set a view's height match parent in ConstraintLayout?

查看:88
本文介绍了如何在ConstraintLayout中设置视图的高度匹配父对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 layout .我要将我的自定义 toolbar (这是另一种布局)设置为 layout 的顶部 FrameLayout (位于工具栏下方).但是 FrameLayout 应该得到 layout 高度的其余部分(match_parent).如何使用约束布局实现这一目标?

I am creating a layout.I want to set my custom toolbar(Which is another layout) to the top of layout and the FrameLayout just below the toolbar. But the FrameLayout should get rest of the layout's height (match_parent). How to achieve this using constraint layout ?

推荐答案

解决方案:我假设您将工具栏作为另一个xml文件,如下所示:

Solution: I'm assuming that you have your toolbar as another xml file, something like this:

toolbar.xml

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="60dp"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

然后使用 ConstraintLayout FrameLayout 一起使用,如下所示:

then using ConstraintLayout use it with FrameLayout like this:

<?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"
    tools:context=".MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar" />

</android.support.constraint.ConstraintLayout>

希望这会有所帮助.如果您有任何疑问,请发表评论.

Hope this helps. Please comment if you have any issues with it.

这篇关于如何在ConstraintLayout中设置视图的高度匹配父对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆