Home > Mobile >  Transparent or Invisible
Transparent or Invisible

Time:02-07

I'm trying to use an ImageView without any background. I know that I can use

imageView.setVisibility(INVISIBLE);

and

imageView.setBackgroundColor(Color.TRANSPARENT);

I was wondering which one is more efficient? or any extra solution?

CodePudding user response:

The two lines don't have the same purpose, so you don't really have to compare their efficiency.

The first one changes the view visibility, so the entire view is still drawn, takes the space in the layout, but is not visible at the moment.

On the other hand, an ImageView with an invisible background can still be visible if it has an android:src that is not null.

Here is a random example that uses the two together: it's an imageview with a transparent background, but with a source image, for which the visibility changes based on a certain condition, so it can be INVISIBLE or VISIBLE:

 <ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:visibility="@{!obj.mealbox}"
      android:background="@android:color/transparent"
      android:src="@drawable/ic_list_sorting_close"
      app:tint="@color/dish_icon_color" />

Since your purpose is to

use an ImageView without any background.

only the second option will work.

CodePudding user response:

you can use imageView.setAlpha(127);

  •  Tags:  
  • Related