[問題] 關於ImageView被CardView覆蓋

作者: lee16818 (afkk)   2020-08-11 03:12:17
各位先進晚安,小魯最近在實作類似Between回憶錄的功能
小魯原本是將ImageView放進CardView中實現的,
但後來發現這與Between的回憶錄不同(個人認為Between的會比較好看)
而我與Between的不同在於,他的圖片其實會跑出CardView之外,
因次我試著將ImageView放到外層的Layout中,但卻發現ImageView會被CardView所覆蓋
因此想上來請教,是否有方法或是關鍵字查詢能讓小魯知道如何將ImageVIew顯示到最上

麻煩各位大德伸出援手了!
(下圖為本人實作)
https://i.imgur.com/uFYyWEA.jpg
(下圖為Between樣板)
https://i.imgur.com/cqwaOPv.jpg
附上XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schem
as
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/c1"
android:layout_width="match_parent"
android:layout_height="325dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="275dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/Card">
<ImageView
android:id="@+id/Picture"
android:layout_width="match_parent"
android:layout_height="275dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/baseline_insert_photo_white_18dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
android:id="@+id/Card"
android:layout_width="375dp"
android:layout_height="300dp"
app:cardElevation="30px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_gravity="bottom"
android:layout_marginLeft="350dp"
android:alpha="0.5"
android:background="@drawable/baseline_more_vert_black_18dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_gravity="bottom"
android:alpha="0.2"
android:background="@drawable/lider2"
android:textStyle="italic" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="350dp"
android:layout_height="275dp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="30dp">
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
作者: zcbxvsdf (東北一頭羊)   2020-08-11 08:44:00
https://link.medium.com/4S6IElPMQ8CardView是ViewGroup, 你要把Imageview包進去當他的子View, 你這樣只是覆蓋而已
作者: gcobc12632 (Ted)   2020-08-11 14:02:00
不要把Imageview包在CardView內 然後有兩種做法一種是 CardView app:cardElevation="0dp"另一種是 ImageView android:elevation="2dp"大概像這樣 https://i.imgur.com/Pdh0bmG.png不知道是不是你要的效果

Links booklink

Contact Us: admin [ a t ] ucptt.com