【发布时间】:2020-01-20 23:18:17
【问题描述】:
我正在尝试在 RecyclerView 上显示一些 png 图像,图像具有透明背景,但在设备上运行时显示白色背景!!。 我尝试添加
android:background="@android:color/transparent"
到 ImageView,但仍然是白色
我使用 Picasso 将图像加载到 ImageView 上,就像那样
Picasso.get()
.load(newpath)
.into(itemView.imgMCat)
这是包含 RecyclerView 的片段
<?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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/meskback"
tools:context=".HomeFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<Toolbar
android:id="@+id/toolbar"
android:background="@color/meskBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
tools:targetApi="lollipop">
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="right"
android:layout_margin="7dp"
android:id="@+id/mapiconbtn"
android:background="@drawable/mapicon"
/>
</Toolbar>
<LinearLayout
android:layout_weight="6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/mainActivityRelayout1"
android:paddingTop="10dp"
android:layout_weight="5">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
tools:srcCompat="@drawable/logo"
android:id="@+id/logoimg"
android:contentDescription="@string/logoimgdes"
android:src="@drawable/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="5"
android:weightSum="2">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:textSize="22sp"
android:layout_weight="1"
android:textStyle="bold"
android:gravity="center"
android:textColor="@color/meskBlue"
android:text="@string/welcome"
android:textAlignment="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="20dp"
android:text="@string/how_can_we_help_you"
android:textAlignment="center"/>
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/McatRecylceView"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
这是包含 ImageView 的 item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="140dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgMCat"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/transparent"
android:layout_centerInParent="true"
android:layout_marginTop="3dp" android:layout_marginStart="3dp"
android:layout_marginEnd="3dp" android:layout_marginBottom="3dp"/>
<TextView
android:text="TextView"
android:id="@+id/mcategoryTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imgMCat"
android:textAlignment="center"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
此设备照片
【问题讨论】:
-
您能分享您的完整 XML 文件吗?
-
这也取决于您在 AndroidManifest.xml 中为 Activity 设置的内容。还要检查您是否没有更改类内代码中的背景颜色。
-
@TaslimOseni 我加了,请查收
-
@MikeM。如果你的意思是 png 图片,这是miskaldar.com/uploadimg/mcategory/1547760850.png
-
从图片上很难看出来:
CardView还有什么别的吗?该卡可以提供纯色/不透明背景。