如何在 android studio 中将半重叠图像创建到 cardview
How to create half overlapped Image to a cardview in android studio
我想在 android 工作室做这样的东西 谁能帮我?
如何将该图像放置在该卡片视图的左侧?
好的,首先,分解你的布局结构,理解层。
具有horizontal
重力(即:LinearLayout)或相对布局的Parent布局。
并且作为 child 观看次数-
A Fixed size moon(ie: 100dp).
A Card view with layoutMarginStart="-50dp"(half the moon).
从逻辑上讲,这应该可行。
--如果月亮在卡片下方,则使用高于卡片的高度。
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>
您可以使用带有辅助线或负边距的 ConstraintLayout 来实现此 XML 视图。
我想在 android 工作室做这样的东西 谁能帮我?
如何将该图像放置在该卡片视图的左侧?
好的,首先,分解你的布局结构,理解层。
具有horizontal
重力(即:LinearLayout)或相对布局的Parent布局。
并且作为 child 观看次数-
A Fixed size moon(ie: 100dp).
A Card view with layoutMarginStart="-50dp"(half the moon).
从逻辑上讲,这应该可行。
--如果月亮在卡片下方,则使用高于卡片的高度。
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>
您可以使用带有辅助线或负边距的 ConstraintLayout 来实现此 XML 视图。