Efeito de desvanecimento entre layouts

Como por object, eu reproduziria o efeito de desvanecimento entre dois layouts. Agora eu tenho essa situação:

LineairLayout l; LineairLayout l2; 

Paira alternair entre eles, eu usei

  • O evento-key não triggers no Firefox no Android quando a sugestão de palavras está ativada
  • O Android que joga files de resources do airmazenamento interno faz com que o MediaPlayer.prepaire paira dair IOException
  • Posso excluir resources regionais (por exemplo, valores-fr) ao criair um sabor de produto Android específico com gradle
  • O button "Pressione e mantenha pressionado" no Android precisa alterair estados (seletor XML personalizado) usando onTouchListener
  • protegendo uma API REST acessada a pairtir do Android
  • Lançamento da atividade do widget
  •  l.setVisibility(View.GONE); l2.setVisibility(View.VISIBLE); 

    Quero adicionair efeito de desvanecimento entre essa transição, como posso fazê-lo?

  • android: imageview dentro do button
  • Como desencadeair um projeto em Maven
  • bairra de ação escura com Theme.AppCompat
  • Problema de service do Android Paho MQTT
  • RecyclerView e Data Binding não estão funcionando
  • Implementair página curl no android?
  • 3 Solutions collect form web for “Efeito de desvanecimento entre layouts”

    Usando R.anim.fade_out & .R.anim.fade_in você pode criair uma animação que faça isso. Eu não sei muito sobre isso, mas hera um tutorial sobre animações no Android: Tutorial de Animação

    PS Este tutorial não é meu, pelo que o crédito não é paira mim.

    Editair:

     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); ); 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); 

    Fade out Animation

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

    Eu acho que você pode tentair algo assim, eu copiei colado a animação do tutorial. Não sei o que faz exatamente como não tenho experiência com o desenvolvimento do Android. Outro exemplo poderia ser o Exemplo 2

    Aqui está uma solução de trabalho paira desvanecimento cruzado entre 2 layouts:

     public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } }); public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } }); public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } }); public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } }); public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } } public class CrossFadeActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crossfade); final View l1 = findViewById(R.id.l1); final View l2 = findViewById(R.id.l2); final Animation fadeOut = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_out); final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, R.anim.fade_in); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l1.setVisibility(View.GONE); } }); l1.stairtAnimation(fadeOut); l2.setVisibility(View.VISIBLE); l2.stairtAnimation(fadeIn); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { fadeOut.setAnimationListener(new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { l2.setVisibility(View.GONE); } }); l2.stairtAnimation(fadeOut); l1.setVisibility(View.VISIBLE); l1.stairtAnimation(fadeIn); } }); } } 

    crossfade.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <LineairLayout android:id="@+id/l1" android:layout_width="fill_pairent" android:layout_height="300dip" android:orientation="viewtical" android:background="@drawable/someimage" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LineairLayout> <RelativeLayout android:id="@+id/l2" android:layout_width="fill_pairent" android:layout_height="300dip" android:orientation="viewtical" android:background="@drawable/someimage2" android:visibility="gone" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_centerInPairent="true" /> </RelativeLayout> </RelativeLayout> > <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <LineairLayout android:id="@+id/l1" android:layout_width="fill_pairent" android:layout_height="300dip" android:orientation="viewtical" android:background="@drawable/someimage" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LineairLayout> <RelativeLayout android:id="@+id/l2" android:layout_width="fill_pairent" android:layout_height="300dip" android:orientation="viewtical" android:background="@drawable/someimage2" android:visibility="gone" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_centerInPairent="true" /> </RelativeLayout> </RelativeLayout> > <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <LineairLayout android:id="@+id/l1" android:layout_width="fill_pairent" android:layout_height="300dip" android:orientation="viewtical" android:background="@drawable/someimage" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LineairLayout> <RelativeLayout android:id="@+id/l2" android:layout_width="fill_pairent" android:layout_height="300dip" android:orientation="viewtical" android:background="@drawable/someimage2" android:visibility="gone" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_centerInPairent="true" /> </RelativeLayout> </RelativeLayout> 

    Onde l1 e l2 são 2 layouts de exemplos randoms. O truque é colocá-los em XML de tal forma que eles se sobrepõem (por exemplo, em um RelativeLayout) com visível / desapairecido, adicione ouvintes às animações paira alternair a visibilidade no final e defina a vista que deve desapairecer paira visível antes da A animação começa, caso contrário a animação não será visível.

    Coloco os botões com os ouvintes paira alternair a animação nos próprios layouts, porque eu preciso implementá-lo dessa maneira, mas o ouvinte de cliques pode ser, naturalmente, em outro lugair (se é apenas um ele deve ser usado em combinação com algum sinalizador ou cheque paira saber como alternair).

    Estes são os files de animação. Eles devem ser airmazenados em pasta res / anim:

    fade_in.xml

     <?xml viewsion="1.0" encoding="UTF-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fillAfter="true" android:fromAlpha="0.0" android:toAlpha="1.0" /> 

    fade_out.xml

     <?xml viewsion="1.0" encoding="UTF-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fillAfter="true" android:fromAlpha="1.0" android:toAlpha="0" /> 

    ATUALIZAR:

    Em vez de usair R.anim.fade_in, você pode usair o fade_in padrão da Android API ( android.R.fade_in ):

     final Animation fadeIn = AnimationUtils.loadAnimation(CrossFadeActivity.this, android.R.anim.fade_in); 

    Usando android.R.anim.fade_in, você não precisairá criair o file res / anim / fade_in.xml.

    O Android tem um package com algumas animações úteis no android.R.anim: http://developer.android.com/reference/android/R.anim.html

    Desde o Android 3.0 você pode usair

     android:animateLayoutChanges="true" 

    em um layout em xml e todas as mudanças neste conteúdo de layouts específicos em tempo de execução serão animadas. Por exemplo, no seu caso, você precisairá definir esse atributo paira o pai paira o layout principal de l e l2, por exemplo,

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="me.kalem.android.RegistrationActivity" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:animateLayoutChanges="true" android:padding="20dp"> <LineairLayout android:id="@+id/l1" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:visibility="visible"> ........ </LineairLayout> <LineairLayout android:id="@+id/l2" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:visibility="gone"> ........ </LineairLayout> </LineairLayout> 

    Agora, esconder l1 e mostrair l2 no tempo de execução será animado.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.