android - ConstraintLayout 中的 FrameLayout wrap_content

标签 android android-constraintlayout android-framelayout

我在 CoordinatorLayout 中的 FrameLayout 不想成为 wrap_content。当我使用 ui 工具选择 wrap_content 时,它不会将其设置为 wrap_content,而是将定义的高度设置为 48dp

我还尝试直接在 xml 文件中设置它并且它有效......直到我重新打开文件。我想 AS 的编辑器正在做一些工作并将其高度重置为 48dp

我的布局是这样的:

<layout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <import type="android.view.View" />
        <variable
            name="viewModel"
            type="com.mydomain.relationViewModel" />

    </data>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true"
            android:layout_centerInParent="true"

            android:visibility="@{viewModel.isLoading() ? View.VISIBLE : View.GONE}"/>

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="@{viewModel.isLoading() ? View.INVISIBLE : View.VISIBLE}">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/hint"
                tools:text="Relation"
                android:layout_marginStart="16dp"
                app:layout_constraintLeft_toLeftOf="parent"
                android:layout_marginLeft="16dp"
                android:text="@string/relationship_spinner_hint"
                android:layout_marginTop="16dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="@+id/spinner" />

            <Spinner
                android:layout_width="0dp"
                android:layout_height="48dp"
                android:id="@+id/spinner"
                android:dropDownWidth="match_parent"
                android:layout_marginEnd="16dp"
                app:layout_constraintRight_toRightOf="parent"
                android:layout_marginRight="16dp"
                app:layout_constraintLeft_toRightOf="@+id/hint"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                app:layout_constraintTop_toTopOf="parent"

                app:setOnItemSelectedListener="@{viewModel.relationshipsListener}"/>

            <FrameLayout
                android:layout_width="0dp"
                android:layout_height="48dp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                android:id="@+id/search_fragment_container"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintTop_toBottomOf="@+id/search_patient_title">

            </FrameLayout>

            <Button
                android:text="@string/cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/cancel"
                app:layout_constraintLeft_toLeftOf="parent"
                style="@style/buttonStyle"
                android:layout_marginTop="8dp"
                app:layout_constraintTop_toBottomOf="@+id/search_fragment_container" />

            <TextView
                android:text="@string/search_patient"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/search_patient_title"
                android:layout_marginTop="8dp"
                app:layout_constraintTop_toBottomOf="@+id/spinner"
                android:layout_marginStart="16dp"
                app:layout_constraintLeft_toLeftOf="parent"
                android:layout_marginLeft="16dp"
                tools:text="Recherche du patient"
                style="@style/myTitle" />

        </android.support.constraint.ConstraintLayout>

    </RelativeLayout>

</layout>

这是我的蓝图的屏幕截图(其中选择的布局是 FrameLayout):

Blueprint

感谢您的进一步帮助!

编辑 CardView 也有同样的问题(似乎是合法的,因为它是 FrameLayout 的 child )。

最佳答案

因为这个Google bug ticket是说:

Fixed in master.

Released with Android Studio 2.3 beta 1

关于android - ConstraintLayout 中的 FrameLayout wrap_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40179207/

相关文章:

android - Volley Post 请求,发送 Json 数组请求中的 Json 对象

android - 如何在 ConstraintLayout 中制作具有最小高度的可拉伸(stretch) View ?

android - TextViews不在约束布局中移至“开始”位置

android - 以编程方式重新约束约束布局中的 View

android - 定义布局内容区域

android: kSOAP 如何从 kSOAP 响应返回的字符串中获取国家/地区列表

android - 切换到 Gradle : why do I have to keep custom views from being obfuscated?

android - AsyncHttpRequest POST 不触发回调(loopj 的 android-async-http)

java - 安卓 : Text in ForeGround of a FrameLayout (contain a googleMap)

android - 如何在 Activity View 中重绘 Canvas