android - Android ConstraintLayout-2.0.0-alpha4 Fragment 与父级不匹配
问题描述
my 的布局Fragment
是ConstraintLayout
宽度和高度都设置为match_parent
.
里面是另一个ConstraintLayout
用来制作固定尺寸比例的区域。
它在 中完美运行ConstraintLayout-2.0.0-alpha3
,但是在我更改为 alpha4 后,外部 ConstrainLayout 与父级不匹配。大约 70% 的原始大小对齐左上角,我不知道为什么。
片段附在 a 上FrameLayout
,大小FrameLayout
合适。
这是我的布局。
<?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>
解决方案
尝试这个
<?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>
推荐阅读
- spring-boot - 1 个 Spring Boot 应用程序中的 Spring mvc 和 webflux
- angular - Angular CLI 6.0.1 如何控制开发环境和 webpack
- r - 禁用绘图缓存
- python - 从 txt 文件中读取和订购向量
- javascript - nodeJS 使代码在隔离的 vm 上下文中运行或创建特定的全局变量
- opendaylight - 尝试运行 karaf 0.8.1 时权限被拒绝
- javascript - 使用 lodash 的 _sortBy 按不同的字段对数组进行排序
- go - 在传递指向切片的指针时出现意外行为
- javascript - 反应 - zIndex 不起作用
- java - 如何修复错误:在 Windows 8.1 版本的“(null)”中找不到所需版本的 Java(TM) 2 运行时环境