Android線性佈局ConstraintLayout必須指定三個位置的相對

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="#000000"
    tools:context=".MainActivity">

    <RelativeLayout
        android:id="@+id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/theme_music"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/media_bg1"
            android:contentDescription="@string/music"
            android:visibility="gone"
            />
        <ImageView
            android:id="@+id/theme_fm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/media_bg2"
            android:contentDescription="@string/fm"
            android:visibility="gone"
            />
    </RelativeLayout>
    <ImageView
        android:id="@+id/lyric_view"
        android:layout_width="wrap_parent"
        android:layout_height="wrap_parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />
</androidx.constraintlayout.widget.ConstraintLayout>

增加三個方向的限制佈局,一般採用上、左、右

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章