Android 相對佈局RelativeLayout 程式碼示例

一贴灵發表於2024-04-10

文字分別放在左上,右上,中間,左下,右下五個地方;

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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=".MainActivity">


    <TextView
        style="@style/RelativeLayoutDemo1Item"
        android:text="default" />

    <TextView
        style="@style/RelativeLayoutDemo1Item"
        android:layout_alignParentEnd="true"
        android:text="layout_alignParentEnd" />

    <TextView
        style="@style/RelativeLayoutDemo1Item"
        android:layout_centerInParent="true"
        android:text="layout_centerInParent" />

    <TextView
        style="@style/RelativeLayoutDemo1Item"
        android:layout_alignParentBottom="true"
        android:text="layout_alignParentBottom" />

    <TextView
        style="@style/RelativeLayoutDemo1Item"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:text="layout_alignParentBottom | End" />
</RelativeLayout>

相關文章