android - Pixel 和 Nexus 手机上的 Android 布局混乱
问题描述
我在下面的图片中出现了这种奇怪的行为,只有在任何谷歌手机上,不管是旧的还是新的,都没关系,它只是错误地出现。可悲的是,它在其他所有手机上都按预期显示。恼人的是它在设计中正确地出现在图像中,但每个人都知道设计永远不会在 xml 中反映现实,另一个恼人的是它是如此简单,根是 CoordinatorLayout 而文本只是在根 :/
这是xml代码
<androidx.coordinatorlayout.widget.CoordinatorLayout(This layout is the )
android:layout_width="match_parent"
android:layout_height="match_parent"
app:touchListener="@{0L}"
>
.
.
.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"
android:background="@color/color_primary"/>
解决方案
由于这是一个约束布局,您应该放置start
,end
和top
约束以获得正确的结果。
示例代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout(This layout is the )
android:layout_width="match_parent"
android:layout_height="match_parent"
app:touchListener="@{0L}"
>
.
.
.
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Some Text"
android:background="@color/color_primary"/>
像这样格式正确的东西对你有用。快乐编码!:)
推荐阅读
- zip - 以递归方式提取 ZIP 文件和 ZIP... 压缩文件,然后删除原始档案
- wordpress - WordPress 自定义帖子类型前端
- algorithm - 使用随机枢轴快速排序对大小为 n 的数组进行排序的比较次数?
- angular - 无法从 Angular 12 升级到 Angular 13
- flutter - FAILURE:构建失败并出现异常。无法解析所有文件以进行配置
- amazon-web-services - 使用 MWS 密钥的 Amazon SP API 身份验证
- amazon-web-services - 带/不带访问密钥和秘密访问密钥的 AWS Cognito InitiateAuth
- r - BigQuery 和 R Shiny - 让用户为查询付费
- django - 我想在 django 的 settings.py 文件中获取当前 url
- python - Python 简单的基础到基础转换器不返回任何结果