簡體   English   中英

我需要android布局配置

[英]I need android layout configurations

在此處輸入圖片說明

70% 30% 布局是用 LinearLayout 的權重和做的。 但是,圖像布局不能疊加在它上面。 我做錯了嗎?

您可以使用ContraintLayout以獲得更大的靈活性。

使用app:layout_constraintHeight_percent屬性以百分比表示高度

您可以使用以下代碼在兩個布局之間對齊Image

    app:layout_constraintBottom_toTopOf="@id/layout2"
    app:layout_constraintTop_toBottomOf="@id/layout1"

這是實現您提到的布局的完整代碼。

    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toTopOf="@id/layout2"
        app:layout_constraintHeight_percent="0.7"             // 70% of height
        app:layout_constraintTop_toTopOf="parent">

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHeight_percent="0.3"             // 30% of height
        app:layout_constraintTop_toBottomOf="@id/layout1">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="center" />

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="center"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp" />

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="center" />
    </LinearLayout>

    <ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        // To align image between layout1 and layout2  
        app:layout_constraintBottom_toTopOf="@id/layout2"
        app:layout_constraintTop_toBottomOf="@id/layout1" />

</android.support.constraint.ConstraintLayout>

樣本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM