Transparent or Invisible

124
April 26, 2022, at 10:00 PM

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?

Answer 1

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.

Answer 2

you can use imageView.setAlpha(127);

Rent Charter Buses Company
READ ALSO
how to use tap method instead of click method in appium?

how to use tap method instead of click method in appium?

I'm trying to automate an android test in appium and I have selected the webdriver as in wd/hub for this purposeHowever, the tap method there is virtually the click method as all the auto-recorded steps are generated as clicks instead of tap / touch

90
Does assetlinks.json file for Android App Links have a size limit like the iOS counterpart?

Does assetlinks.json file for Android App Links have a size limit like the iOS counterpart?

In order to only allow authorized apps to open https links, Android has App Links, and iOS has Universal LinksIn both, one needs to upload a file, viz

94
gradle: Duplicate value for resources coming from multiple external libraries

gradle: Duplicate value for resources coming from multiple external libraries

I have a situation where I am trying to add two dependencies that have resources conflict

118