【发布时间】:2021-05-24 11:34:27
【问题描述】:
【问题讨论】:
-
你想让布局像上面提到的图像
标签: android android-layout android-cardview
【问题讨论】:
标签: android android-layout android-cardview
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>
【讨论】:
好的,首先,分解你的布局结构并了解层。
具有horizontal 重力的父布局(即:LinearLayout)或相对布局。
作为子视图-
A Fixed size moon(ie: 100dp).
A Card view with layoutMarginStart="-50dp"(half the moon).
从逻辑上讲,这应该可行。
--如果月亮在卡片下方,则使用比卡片更多的海拔。
【讨论】:
您可以使用带指引线或负边距的 ConstraintLayout 来实现此 XML 视图。
【讨论】: