gpt4 book ai didi

android - android studio中png图像的白色背景

转载 作者:行者123 更新时间:2023-11-30 05:02:27 24 4
gpt4 key购买 nike

我试图在 RecyclerView 上显示一些 png 图像,图像具有透明背景,但在设备上运行时显示白色背景!!我尝试添加

android:background="@android:color/transparent"

到ImageView,但还是白色

我使用 Picasso 将图像加载到 ImageView 上,就像那样

Picasso.get()
.load(newpath)
.into(itemView.imgMCat)

这是包含 RecyclerView 的 fragment

<?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>

这张照片用于设备

enter image description here

最佳答案

我在这里找到了答案,问题出在 CardView https://stackoverflow.com/a/45769769/2209611

我添加了这些属性并解决了问题

app:cardBackgroundColor="@android:color/transparent"
app:cardElevation="0dp"

关于android - android studio中png图像的白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58019194/

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