How can I change the transparency (alpha) of a view on pre-SDK-11 on Android?
Before you suggest using a background colour with some transparency, please note that this method does not include all elements in the view such as the text of a button or the child views of a view group.
setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.
To get α subtract your confidence level from 1. For example, if you want to be 95 percent confident that your analysis is correct, the alpha level would be 1 – . 95 = 5 percent, assuming you had a one tailed test. For two-tailed tests, divide the alpha level by 2.
"alpha" is used to specify the opacity for an image.
Try using an AlphaAnimation : http://developer.android.com/reference/android/view/animation/AlphaAnimation.html
/* Have to use animation in order to get card faded. */
AlphaAnimation alpha = new AlphaAnimation(0.7F, 0.7F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
view.startAnimation(alpha);
The ViewHelper of NineOldAndroids is what I use, it is a static helper class and a real gem! Many here recommend NineOldAndroids but I have seen no mention of the ViewHelper. It is really easy to use.
import com.nineoldandroids.view.ViewHelper;
...
ViewHelper.setAlpha(myView, .2f);
You can also use it to set other properties like x, y etc, very handy when setting up for animations or building your UI. Many thanks to Jake Wharton for sharing his work with the community!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With