android - Android:layout_centerHorizontal vs layout_centerVertical
问题描述
android:layout_centerVertical="true"
在 a中使用时,Relativelayout
它不起作用。但是,当我将其更改为 android:layout="true"
完美运行时,这是为什么呢?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:textAppearanceLarge"
android:text="Happy" />
</RelativeLayout>
我在Udacity上进行试验,并尝试使用ndroid:layout_centerVertical/Horizontal="true"
仅水平布局有效,但我不明白为什么。我仍然是初学者(1 周),所以希望得到解释。泰
解决方案
当使用android:layout_centerVertical="true"
removeandroid:layout_alignParentTop="true"
和放置水平居中 remove android:layout_alignParentRight="true"
。与侧面对齐比中心垂直/水平具有更高的优先级
推荐阅读
- math - 我有一个网格,如何找到适合球体的最深点?
- terraform - Terraform 错误:“提供者不支持资源:gsuite_group_settings”
- c - C2440 编译器错误仅适用于新项目,但不适用于现有项目
- mysql - 在连接到 sql 数据库时运行 docker compose up 时出错
- python - QTreeView:检查要删除的项目是否已经存在并在 dropEvent() 上避免它
- workbox - 工作箱不匹配任何东西
- laravel - 在 laravel 的产量部分中传递图像
- javascript - AJAX Vanilla JavaScript - 仅在第一个已发送后才发送 2cnd 异步帖子
- python - SymPy 中更难的方程(带导数和积分)和条件集
- linux - Celery systemd 正确配置两个应用程序使用相同的守护程序服务