【问题标题】:Put layout over another layout in constraint layout将布局放在约束布局中的另一个布局上
【发布时间】:2020-02-29 12:56:00
【问题描述】:

我不想这样布局:

当我创建约束布局时,它会将图像置于模态视图顶部对齐的中心。

我终于做到了,但我无法将标题对齐到图像底部,因为它存在于父布局中。

如何像第一张图片一样创建布局?

【问题讨论】:

标签: android


【解决方案1】:

试试这个

<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>

希望对你有帮助!

谢谢。

【讨论】:

    【解决方案2】:

    尝试实现下面的例子可能会奏效

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 2017-02-02
      相关资源
      最近更新 更多