首页 > 解决方案 > Android:layout_centerHorizo​​ntal 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

解决方案


当使用android:layout_centerVertical="true"removeandroid:layout_alignParentTop="true"和放置水平居中 remove android:layout_alignParentRight="true"。与侧面对齐比中心垂直/水平具有更高的优先级


推荐阅读