0

I want to my first page background fade out and then going to next page. I make shape with gradient and use it for background of first page. but when I run my app in genymotion background color of first page is dark gray,I am new to Android development so I don't have much idea to how can handle it. XML :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

 <gradient
    android:centerX="20%"
    android:endColor="#aed36c"
    android:startColor="#44c8f5" />
</shape>

MAINACTIVITY XML :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/linergradiant"
android:id="@+id/firstpage"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/texture" >

    <LinearLayout
        android:layout_width="200dip"
        android:layout_height="200dip"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginTop="116dp"
        android:background="@drawable/logo_big2" >
    </LinearLayout>

 </RelativeLayout>

</LinearLayout>

MAINACTIVITY JAVA

public class MainActivity extends ActionBarActivity {
 LinearLayout screen;
 Handler handler = new Handler();
 int i;
 Intent intent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    screen=(LinearLayout) findViewById(R.id.firstpage);
    (new Thread(){
        @Override
    public void run(){
        for(i=0; i<255; i=i+3){
            handler.post(new Runnable(){
                public void run(){
                    screen.setBackgroundColor(Color.argb(255, i, i, i));
                }
            });
            try{ sleep(100); }
               catch(Exception e){ break; }
            }
            startActivity(new Intent(getApplicationContext(),BMIcalculator.class));
        }
    }).start();     
}
}

can any one help me? can it solve with transition ??

mkafiyan
  • 944
  • 2
  • 9
  • 31

1 Answers1

0

Refer the following code from here

private View mContentView;
private View mLoadingView;
private int mShortAnimationDuration;

...

private void crossfade() {

    // Set the content view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    mContentView.setAlpha(0f);
    mContentView.setVisibility(View.VISIBLE);

    // Animate the content view to 100% opacity, and clear any animation
    // listener set on the view.
    mContentView.animate()
            .alpha(1f)
            .setDuration(mShortAnimationDuration)
            .setListener(null);

    // Animate the loading view to 0% opacity. After the animation ends,
    // set its visibility to GONE as an optimization step (it won't
    // participate in layout passes, etc.)
    mLoadingView.animate()
            .alpha(0f)
            .setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mLoadingView.setVisibility(View.GONE);
                }
            });
}
rupesh jain
  • 3,410
  • 1
  • 14
  • 22