看板 AndroidDev 關於我們 聯絡資訊
各位先進晚安,小魯最近在實作類似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> -- Sent from my Windows -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.137.234.14 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1597086739.A.9B6.html ※ 編輯: lee16818 (223.137.234.14 臺灣), 08/11/2020 03:13:40
zcbxvsdf: https://link.medium.com/4S6IElPMQ808/11 08:44
zcbxvsdf: CardView是ViewGroup, 你要把Imageview包進去當他的子Vi08/11 08:49
zcbxvsdf: ew, 你這樣只是覆蓋而已08/11 08:49
我知道包進去沒問題,但我希望能讓圖片的寬度不受CardView限制,意旨照片有可能會超 過CardView的邊界,這樣是辦得到的嗎? ※ 編輯: lee16818 (223.137.234.14 臺灣), 08/11/2020 13:28:30
gcobc12632: 不要把Imageview包在CardView內 然後有兩種做法08/11 14:02
gcobc12632: 一種是 CardView app:cardElevation="0dp"08/11 14:03
gcobc12632: 另一種是 ImageView android:elevation="2dp"08/11 14:03
gcobc12632: 大概像這樣 https://i.imgur.com/Pdh0bmG.png08/11 14:07
gcobc12632: 不知道是不是你要的效果08/11 14:07
是! 感謝大大,上了一課 ※ 編輯: lee16818 (223.137.234.14 臺灣), 08/11/2020 14:36:37