我是在 android 上编程的新手,所以我很难理解相对布局是如何工作的。我已经解决了大部分问题,但是当我尝试在我的代码中使用它时, android:layout_centerVertical="true" 只是不起作用。我应该从上到下按顺序放置 3 个文本视图,所以它说“祝你生日快乐”,但我无法将“生日”文本视图放在左中。当我使用 android:layout_centerInParent="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_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:textAppearanceLarge"
android:text="Happy" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:textAppearance="?android:textAppearanceLarge"
android:text="Birthday" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:textAppearance="?android:textAppearanceLarge"
android:text="To You" />
试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center" // settext gravity as per your requirement
android:text="Happy"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:gravity="center"// settext gravity as per your requirement
android:text="Birthday"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center" // settext gravity as per your requirement
android:text="To You"
android:textAppearance="?android:textAppearanceLarge" />
</RelativeLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句