gpt4 book ai didi

android - 将 RecyclerView CardView 背景更改为透明

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:00 25 4
gpt4 key购买 nike

问题简版:

I want to make my CardView and RecyclerView background transparent, so the fragment/activity background should become visible.

解释:

我有一个带有背景图像的 Activity A 并且 fragment B 在其 Framelayout 上被替换,在 fragment B 我有 recyclerViewCardView 现在的问题是我想让每个背景透明 所以只有 CardView 在 Activity 的实际背景下可见

RecyclerView 看起来像这样(这些白色背景应该是透明的): recyclerView_Card

代码

Activity (A)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:backgroundTint="@android:color/transparent"/>

fragment (B) RecyclerView

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="@android:color/transparent"
android:background="@android:color/transparent">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
tools:listitem="@layout/layout_video_item"
android:backgroundTint="@android:color/transparent"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextView
android:id="@+id/tv_not_found"
android:text="No Media Found Yet"
android:layout_gravity="center"
android:gravity="center"
android:visibility="gone"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</android.support.design.widget.CoordinatorLayout>

CardView/项目布局

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:layout_marginStart="3dp"
android:layout_marginTop="3dp"
android:background="@android:color/transparent">

<android.support.v7.widget.CardView
style="@style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
android:background="@android:color/transparent"
android:backgroundTint="@android:color/transparent"
app:cardCornerRadius="5dp"
android:padding="0dp"
app:cardElevation="0dp"
tools:ignore="ContentDescription">

<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@color/colorAccent">

<ImageView
android:id="@+id/media_image"
android:layout_width="100dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:color/darker_gray" />

<ImageButton
android:id="@+id/ib_delete"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#00FFFFFF"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_delete_white_24dp" />

<ImageButton
android:id="@+id/share_button"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#00FFFFFF"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ib_delete"
app:srcCompat="@drawable/ic_share_white_24dp" />

<TextView
android:id="@+id/tv_video_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Title Test"
android:textAppearance="@style/TextAppearance.AppCompat.Large.Inverse"
android:textColor="@color/colorPrimaryText"
app:layout_constraintEnd_toStartOf="@+id/tv_ribbon"
app:layout_constraintStart_toEndOf="@+id/media_image"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_ribbon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
android:ellipsize="marquee"
android:fontFamily="monospace"
android:padding="3dp"
android:singleLine="true"
android:text="New"
android:textColor="@color/colorIcons"
android:textSize="14sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_path"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="5dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="subtitle test"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/media_image"
app:layout_constraintTop_toBottomOf="@+id/tv_video_name" />

<ImageView
android:id="@+id/iv_is_audio"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="5dp"
android:layout_marginTop="8dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/media_image"
app:layout_constraintTop_toBottomOf="@+id/tv_duration"
app:srcCompat="@drawable/ic_settings_voice_black_24dp" />

<ImageView
android:id="@+id/iv_is_video"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="5dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/iv_is_audio"
app:layout_constraintStart_toEndOf="@+id/iv_is_audio"
app:layout_constraintTop_toTopOf="@+id/iv_is_audio"
app:srcCompat="@drawable/ic_theaters" />

<ImageView
android:id="@+id/iv_is_gif"
android:layout_width="35dp"
android:layout_height="30dp"
android:layout_marginStart="5dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/iv_is_video"
app:layout_constraintStart_toEndOf="@+id/iv_is_video"
app:layout_constraintTop_toTopOf="@+id/iv_is_video"
app:srcCompat="@drawable/ic_gif" />

<TextView
android:id="@+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="8dp"
android:text="0:00"
app:layout_constraintStart_toEndOf="@+id/media_image"
app:layout_constraintTop_toBottomOf="@+id/tv_path" />

<TextView
android:id="@+id/tv_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="0 MB"
app:layout_constraintBottom_toBottomOf="@+id/tv_duration"
app:layout_constraintStart_toEndOf="@+id/tv_duration"
app:layout_constraintTop_toTopOf="@+id/tv_duration" />


</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>

</RelativeLayout>

提问的原因:

我知道有很多 SO 问题可以完成同样的任务,但我的要求略有不同,问这个问题的原因是没有什么对我有用。

期待

最佳答案

将 CardView 背景设置为 app:cardBackgroundColor="#00ffffff"

关于android - 将 RecyclerView CardView 背景更改为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49150014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com