Android ConstraintLayout-2.0.0-alpha4片段与父项不匹配

时间:2019-04-18 10:33:11

标签: android android-layout

我的Fragment的布局是ConstraintLayout,宽度和高度均设置为match_parent

里面是另一个ConstraintLayout,用于制作固定的尺寸比例区域。

它在ConstraintLayout-2.0.0-alpha3中可以很好地工作,但是在我更改为alpha4之后,外部的ConstrainLayout与父项不匹配。大约是原始尺寸的70%,左对齐,我不知道为什么。

该片段附加到FrameLayoutFrameLayout的大小正确。

这是我的布局。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".KeyboardFragment">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@drawable/game_keyboard_bg"
        app:layout_constraintDimensionRatio="1.6129"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <Space
            android:id="@+id/corner_tl"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:1"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintHeight_percent="0.01"/>

        <Space
            android:id="@+id/corner_br"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHeight_percent="0.01"/>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="2:1"
            app:layout_constraintTop_toBottomOf="@+id/corner_tl"
            app:layout_constraintBottom_toTopOf="@+id/corner_br"
            app:layout_constraintStart_toEndOf="@+id/corner_tl"
            app:layout_constraintEnd_toStartOf="@+id/corner_br" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

尝试

<?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.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>