【问题标题】:How to constraint the center of an image between two layouts android如何在两个布局android之间约束图像的中心
【发布时间】:2022-01-13 18:58:33
【问题描述】:

我需要按照屏幕截图所示进行操作,但我不明白该怎么做。我尝试联系baseline,但没有成功。

我的代码在这里:

<androidx.constraintlayout.widget.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rl_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </RelativeLayout>

    <androidx.appcompat.widget.LinearLayoutCompat
        android:id="@+id/top_layout"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="@color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/rl_bar">

    </androidx.appcompat.widget.LinearLayoutCompat>

    <androidx.appcompat.widget.LinearLayoutCompat
        android:id="@+id/bottom_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/elegant_black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/top_layout">

    </androidx.appcompat.widget.LinearLayoutCompat>

    <de.hdodenhof.circleimageview.CircleImageView
        android:src="@color/elegant_black"
        app:layout_constraintBaseline_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

我该怎么做?

截图示例:

这是我得到的:

【问题讨论】:

    标签: android xml android-linearlayout android-relativelayout android-constraintlayout


    【解决方案1】:

    我们开始吧。尝试这个。干杯。

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginStart="20dp"
            android:background="@color/elegant_black"
            app:civ_border_color="@android:color/white"
            app:civ_border_width="2dp"
            app:layout_constraintBottom_toTopOf="@id/bottom_layout"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/top_layout" />
    

    【讨论】:

    • 它有效,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多