将布局放在约束布局中的另一个布局上

我不会这样布局:

将布局放在约束布局中的另一个布局上

当我创建约束布局时,它将图像放置在modalview顶部对齐的中心。

将布局放在约束布局中的另一个布局上

最后我做到了,但是我无法将标题的对齐方式更改为图像的底部,因为它出现在父版式中。

如何在第一张图片中创建布局?

taitan_winter 回答:将布局放在约束布局中的另一个布局上

尝试一下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp">

    <!--Your Details Screen Layout-->
    <RelativeLayout
        android:id="@+id/rlMain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp">

    </RelativeLayout>

    <!--Your Top Image View-->
    <androidx.cardview.widget.CardView
        android:id="@+id/cardImg"
        android:layout_width="125dp"
        android:layout_height="150dp"
        android:layout_centerInParent="true"
        app:cardCornerRadius="5dp"
        app:cardElevation="10dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <ImageView
                android:id="@+id/imgGame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY" />
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</RelativeLayout>

希望这对您有帮助!

谢谢。

,

尝试实现以下示例可能会起作用

layout_bg.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#1D2126"/>
        <stroke android:width="3dp" android:color="#B1BCBE" />
        <corners android:radius="10dp"/>
        <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
    </shape>


    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_gravity="center"
        android:foregroundGravity="center">

        <RelativeLayout
            android:id="@+id/imv_background_pic"
            android:layout_width="300dp"
            android:layout_height="400dp"
            android:background="@drawable/layout_bg"
            android:foregroundGravity="center"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="46dp"
            tools:layout_editor_absoluteY="198dp" />

        <ImageView
            android:id="@+id/imv_forground_pic"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/layout_bg"
            android:foregroundGravity="center"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="96dp"
            tools:layout_editor_absoluteY="96dp" />


    </androidx.constraintlayout.widget.ConstraintLayout>
本文链接:https://www.f2er.com/3168254.html

大家都在问