【问题标题】:How to create half overlapped Image to a cardview in android studio如何在android studio中创建半重叠图像到cardview
【发布时间】:2021-05-24 11:34:27
【问题描述】:

我想在 android studio 中制作这样的东西,谁能帮帮我?

如何将该图像放在该卡片视图的左侧?

【问题讨论】:

  • 你想让布局像上面提到的图像

标签: android android-layout android-cardview


【解决方案1】:
Try this out it will work same as you want just replace your UI accordingly 


    <androidx.constraintlayout.widget.ConstraintLayout 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">
    
    
        <androidx.cardview.widget.CardView
            android:id="@+id/cardView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginBottom="2dp"
            android:elevation="@dimen/cardview_default_elevation"
            app:cardBackgroundColor="@color/quantum_pink"
            app:cardCornerRadius="18dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="1.0">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/_20sdp"
                    android:fontFamily="serif"
                    android:text="abcdefghijk"
                    android:textColor="@android:color/black"
                    android:textSize="26sp"
                    android:textStyle="bold"
                    android:translationZ="2dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
                
            </LinearLayout>
    
        </androidx.cardview.widget.CardView>
    
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:adjustViewBounds="false"
            android:elevation="5dp"
            android:src="@mipmap/ic_launcher"
            android:translationZ="5dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/cardView2"
            app:layout_constraintHorizontal_bias="0.098"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
    </androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

  • 是的,它工作得很好,但是我不明白 _20sdp 指的是什么。
  • 好吧,我使用 implementation 'com.intuit.sdp:sdp-android:1.0.6' implementation 'com.intuit.ssp:ssp-android:1.0.6' 来支持不同的屏幕尺寸。您也可以将 _20sdp 替换为简单的 20 dp
【解决方案2】:

好的,首先,分解你的布局结构并了解层。

具有horizontal 重力的父布局(即:LinearLayout)或相对布局。

作为子视图-

A Fixed size moon(ie: 100dp).

A Card view with layoutMarginStart="-50dp"(half the moon).

从逻辑上讲,这应该可行。

--如果月亮在卡片下方,则使用比卡片更多的海拔。

【讨论】:

    【解决方案3】:

    您可以使用带指引线或负边距的 ConstraintLayout 来实现此 XML 视图。

    【讨论】:

    • 最好用一些代码示例来提供答案。建议的东西只能作为评论。
    • 感谢您的建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    相关资源
    最近更新 更多