how to make image transparent?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to make image transparent?

Postby sandis84 » Mon Aug 17, 2009 9:24 am

So I have a checkbox I want to become transparent when it is checked. I want the transparency to come through an animation, so I cant just make the png transparent. That is, when the checkbox is checked it is first to be checked, and then slowly gain transparency through an AlphaAnimation. But then I want it to keep its transparency when the animation is finished. Can you help me do this?

Regards,
Per Sandström
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Top

Postby mangaluve » Mon Aug 17, 2009 9:45 am

One thing you Can do is to set a static alpha-transformation on your view. So you make a fade-animation and when it ends, you tell the parent of your view to give your view a static transformation (with a low alpha).
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby sandis84 » Mon Aug 17, 2009 9:58 am

Thanks for the help. Im sorry, but could you describe how to set a static alpha-transformation?
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Postby mangaluve » Mon Aug 17, 2009 10:27 am

Well you have to override the getChildStaticTransformation of the parent. It's kind of weird though... do you want your CheckBox to disappear completely (alpha=0) or just partially?
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby sandis84 » Mon Aug 17, 2009 10:29 am

Just partially. My objective is a neat todo-list. When an item get checked, it should become transparent through an animation and stay that way until deleted or unchecked.
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Postby sandis84 » Mon Aug 17, 2009 10:41 am

I tried this code, it didnt make the child transparent. How should I edit it?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         class transparentLinearLayout extends LinearLayout{
  2.  
  3.  
  4.  
  5.                 public transparentLinearLayout (Context context) {
  6.  
  7.                         super(context);
  8.  
  9.                 }
  10.  
  11.                 public transparentLinearLayout (Context context, AttributeSet attrs) {
  12.  
  13.                         super(context, attrs);
  14.  
  15.                 }
  16.  
  17.                
  18.  
  19.                 @Override
  20.  
  21.                 protected boolean getChildStaticTransformation(View e, Transformation t) {
  22.  
  23.                         Transformation t2 = new Transformation();
  24.  
  25.                         t2.setAlpha((float) 0.7);
  26.  
  27.                         return super.getChildStaticTransformation(e, t2);
  28.  
  29.                 }
  30.  
  31.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


edit: I tried adding setStaticTransformationsEnabled(true); in the constructor, but it didnt help either.
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Top

Postby mangaluve » Mon Aug 17, 2009 10:59 am

You should try something like this instead
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class transparentLinearLayout extends LinearLayout{
  2.  
  3.          
  4.  
  5.           @Override
  6.  
  7.           protected boolean getChildStaticTransformation(View e, Transformation t) {
  8.  
  9.                t.setAlpha(0.7f);
  10.  
  11.                return true
  12.  
  13.           }
  14.  
  15.      }
  16.  
  17.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

You also have to call setStaticTransformationsEnabled(true) on your parent. But note that with the code above, that alpha-transform will be used for All children of your LinearLayout. So you have to add some conditional statement, to check if the View really should use the transform.

Another way to do it is to extend the CheckBox. Then you can modify the draw-method.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby sandis84 » Mon Aug 17, 2009 11:36 am

Yes, it worked! Thank you very much mangaluve, you really saved me alot of work.
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Postby mangaluve » Mon Aug 17, 2009 12:12 pm

you are welcome
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests