我需要在一個活動的卡片和背景之間顯示一個影像。圖片樣本附在后面。到目前為止,我還在為布局而奮斗。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"?
xmlns:app="http://schemas.android.com/apk/res-auto"。
xmlns:tools="http://schemas.android.com/tools"/span>
android:layout_width="match_parent"/span>
android:layout_height="match_parent"/span>
android:background="#D3E6ED"/span>
tools:context=".MainActivity">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"。
android:layout_height="match_parent"/span>
android:layout_marginStart="10dp"/span>
android:layout_marginTop="120dp"/span>
android:layout_marginEnd="10dp"/span>
app:layout_constraintBottom_toBottomOf="parent"。
app:layout_constraintEnd_toEndOf="parent"。
app:layout_constraintStart_toStartOf="parent"。
app:layout_constraintTop_toTopOf="parent"。
app:cardCornerRadius="10dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
圖片為附件。
uj5u.com熱心網友回復:
將卡片和影像視圖放在同一位置,但在卡片上添加相當于影像視圖高度一半的頂部空白。 在xml中把影像視圖放在第二位,這樣它就會在z排序中位于頂部。
uj5u.com熱心網友回復:
這里有一些接近的輸出。只是你需要按照你的要求改變卡視的形狀。
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"? xmlns:app="http://schemas.android.com/apk/res-auto"/span> xmlns:tools="http://schemas.android.com/tools"/span> android:layout_width="match_parent"/span> android:layout_height="match_parent"/span> android:background="#D3E6ED"> <androidx.cardview.widget.CardView android:id="@ id/cardView"/span> android:layout_width="match_parent"。 android:layout_height="match_parent"/span> android:layout_marginStart="10dp"/span> android:layout_marginTop="120dp"/span> android:layout_marginEnd="10dp"/span> app:cardCornerRadius="10dp"/span> app:layout_constraintBottom_toBottomOf="father"。 app:layout_constraintEnd_toEndOf="parent"。 app:layout_constraintStart_toStartOf="parent"。 app:layout_constraintTop_toTopOf="father" /> <androidx.appcompat.widget.AppCompatImageView android:id="@ id/imageView"/span> android:layout_width="@dimen/_100sdp"/span> android:layout_height="@dimen/_100sdp"/span> android:layout_marginTop="@dimen/_50sdp"/span> android:translationZ="@dimen/_90sdp"/span> app:layout_constraintEnd_toEndOf="parent"。 app:layout_constraintStart_toStartOf="parent"。 app:layout_constraintTop_toTopOf="parent"。 tools:src="@drawable/current_location" /> <androidx.appcompat.widget.AppCompatImageView android:id="@ id/img_camera"。 android:layout_width="@dimen/_20sdp"/span> android:layout_height="@dimen/_20sdp"/span> android:layout_marginEnd="@dimen/_5sdp"/span> android:layout_marginBottom="@dimen/_15sdp"/span> android:tint="@color/black"/span> android:translationZ="@dimen/_90sdp"/span> app:layout_constraintBottom_toBottomOf="@ id/imageView"。 app:layout_constraintEnd_toEndOf="@ id/imageView"。 tools:src="@drawable/ic_icon_camera_attendant" /> </androidx.constraintlayout.widget.ConstraintLayout>uj5u.com熱心網友回復:
implementation 'de.hdodenhof:circleimageview:2.2.0'/span> 使用this庫for圓形影像。這段代碼將解決你的問題。 <?xml version="1.0" encoding="utf-8"? > <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"? xmlns:card_view="http://schemas.android.com/apk/res-auto"。 android:layout_width="match_parent"/span> android:layout_height="match_parent"/span> xmlns:app="http://schemas.android.com/tools"/span> android:background="#f36121"> <RelativeLayout app:layout_constraintTop_toTopOf="parent"。 android:layout_width="match_parent"。 android:layout_margin="20dp"/span> android:layout_height="match_parent"> <androidx.cardview.widget.CardView android:id="@ id/card_login"/span> android:layout_width="match_parent"。 android:layout_height="wrap_content"/span> android:layout_marginTop="50dp"/span> android:foreground="?android:attr/selectableItemBackground"。 card_view:cardBackgroundColor="#ffffff"/span> card_view:cardCornerRadius="4dp"/span> card_view:cardElevation="0dp"。 card_view:cardUseCompatPadding="false" > <LinearLayout android:layout_width="match_parent"/span> android:layout_height="match_parent"/span> android:orientation="vertical""50dp"/span> android:padding="24dp"> <編輯文本 android:layout_width="match_parent"/span> android:layout_height="wrap_content"/span> android:hint="Login"/> <編輯文本 android:layout_width="match_parent"/span> android:layout_height="wrap_content"/span> android:layout_marginTop="16dp"/span> android:hint="Password"/span> android:inputType="textPassword"/> <按鈕 android:layout_width="match_parent"/span> android:layout_height="wrap_content"/span> android:layout_marginTop="16dp"/span> android:text="Sign In"/span> android:background="@android:color/holo_blue_dark" /> </LinearLayout> </androidx.cardview.widget.CardView> <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"。 app:layout_constraintTop_toTopOf="parent"。 app:layout_constraintStart_toStartOf="parent"。 app:layout_constraintBottom_toTopOf="@ id/card_login"/span> app:layout_constraintEnd_toEndOf="parent"。 android:id="@ id/profile_image"/span> android:layout_width="120dp"/span> android:layout_centerInParent="true"/span> android:layout_alignParentTop="true"。 android:layout_height="120dp"/span> android:src="@mipmap/template_icon"/span> app:civ_border_width="10dp"。 android:layout_marginEnd="@dimen/_5sdp"/span> app:civ_border_color="#f36121"/span>/> </RelativeLayout></androidx.constraintlayout.widget.ConstraintLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/328859.html
標籤:


