2012-04-04 6 views
0

ich in einem Zustand festgehalten werde, dass ich nicht das Unter Layout halten verblasste nach der Fade-AnimationShading sub-Layout in android

FrameLayout mapLayout = (FrameLayout)findViewById(R.id.mapLayout); 

Animation fadeAnim = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); 
mapLayout.startAnimation(fadeAnim); 

Bitte führen Wie kann ich dies in Android erreichen. Diese Animation und der schattierte Effekt treten auf, wenn ich auf den "Pause" -Button klicke und um den Effekt umzukehren, drücke ich den "Resume" Button (Sorry, ich habe das Bild mit 'Pause' Button in der schattierten Ansicht gemacht, in Wirklichkeit ist es 'Resume')

enter image description here

Antwort

0

Beide oben genannten Antworten mir geholfen, das Problem bei der Lösung, aber beide Antworten waren nicht die tatsächliche Lösung für mein Problem. Die Lösung, die ich gemacht ist

I definiert zwei Animationen nach meinem Bedürfnis

Animation fadeOut = new AlphaAnimation(0f,0.5f); 
Animation fadeIn = new AlphaAnimation(0.5f,1f); 
fadeOut.setFillAfter(true); 
fadeIn.setFillAfter(true); 

Wenn ich 'Pause' Button geklickt ich folgende Zeile

mapLayout.startAnimation(fadeOut); 

Dann von Pausenzustand fortzusetzen ausgeführt, I folgende Zeile ausgeführt

mapLayout.startAnimation(fadeIn); 

Danke Simon und Deepak!

0

hii makki Sie den Code unten in Ihrem Onclick-Ereignis einstellen

AnimationSet set = new AnimationSet(true); 

Animation animation = new AlphaAnimation(0.0f, 1.0f); 
animation.setDuration(50); 
set.addAnimation(animation); 

animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, 
Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f 
); 
animation.setDuration(100); 
set.addAnimation(animation); 

LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f); 
l.setLayoutAnimation(controller); 

dann verblassen Animation

public static Animation runFadeOutAnimationOn(Activity ctx, View target) { 
    Animation animation = AnimationUtils.loadAnimation(ctx,android.R.anim.fade_out); 
    target.startAnimation(animation); 
    return animation; 
}