问题
I have a transparent image and when I add in my imageview it appears like this
[output image 1]
but I want to remove the white color of the image .I need only the carin the image to be show and remove the white borders and make the layout background to be shown is there any way I can do it.
this is my cardview.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="90dp"
android:layout_height="130dp"
android:layout_margin="5dp"
app:cardCornerRadius="8dp"
app:cardElevation="10dp"
android:id="@+id/cardview">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/category_item"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/cat_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10sp"
android:layout_gravity="center_horizontal"
android:textColor="@color/dark_grey_two"
android:textSize="12sp"/>
</LinearLayout>
回答1:
You could try this layout attribute inside your LinearLayout :
android:background="@android:color/transparent"
This will hide the background color and the white should not be visible anymore.
Give it a shot and let us know if this was helpful.
回答2:
you should make the background of your image transparent by adding background attribute to your Imageview.
<ImageView
android:id="@+id/category_item"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:background="@android:color/transparent"
/>
This will change the default white color background of the image in android studio
回答3:
Use transparent background for ImageView like below:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:background="@android:color/transparent"
android:id="@+id/category_item"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/cat_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10sp"
android:layout_gravity="center_horizontal"
android:textColor="@color/dark_grey_two"
android:textSize="12sp"/>
</LinearLayout>
来源:https://stackoverflow.com/questions/57609754/show-imageview-in-android-studio-without-white-background