Android and set alpha (image) Transparency

Source: Internet
Author: User

1. No, no, how to see the Imageview.setalpha (INT) in the "Related XML Properties" section is missing another method is View.setalpha (floating)/android:alpha instead. However, only because API level 11 is the latter.
2. It is easier than other reactions. There is an XML value alpha that requires double value. The invisible Android:alpha="0.0" Android:alpha="0.5" perspective Android:alpha="1.0" is all visible and that's how it works.
3. I don't know about XML, but you can do this in the following way by code.

ImageView myImageView = new ImageView(this);myImageView.setAlpha(xxx);

0 < range <=255,0 is transparent and 255 is opaque.
4. Perhaps a useful alternative to the background of a pure color: Put the linearlayout in ImageView's linearlayout as an opaque filter. In a small example below, there is a black background:

  <linearlayout xmlns:android= "codego.net android:id=" @+id/layout "Android:layout_ Width= "Match_parent" android:layout_height= "match_parent" android:background= "#FF000000" ><relativelayout Android:id= "@+id/relativelayout2" android:layout_width= "match_parent" android:layout_height= "Wrap_content" > <imageview android:id= "@+id/imageview" android:layout_width= "wrap_content" android:layout_height= "wrap_content "Android:src=" @drawable/icon_stop_big "/> <linearlayout android:id=" @+id/opacityfilter "android:layout_width = "Fill_parent" android:layout_height= "fill_parent" android:background= "#CC000000" android:orientation= "vertical" > </linearlayout></relativelayout>  

Change Android: Background properties between LinearLayout #00000000 (fully transparent) and #ff000000 (completely opaque).
5. There is now an alternative to XML:

  <ImageView  android:id="@+id/example"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:src="@drawable/example"  android:alpha="0.7" />

It is: android:alpha= "0.7" with values from 0 (transparent) to 1 (opaque).
6. Alpha can be set together with the following hexadecimal format argb# or #aarrggbb. See
7. Use this form to get an older version of Android.

ImageView myImageView;myImageView = (ImageView) findViewById(R.id.img);AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);alpha.setDuration(0); alpha.setFillAfter(true); myImageView.startAnimation(alpha);

Android and set alpha (image) Transparency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.