背景后重定向到新页面(渐变形状)淡出

时间:2014-08-12 05:02:32

标签: java android gradient fade shape

我希望我的第一页背景淡出,然后转到下一页。 我用渐变制作形状并将其用作第一页的背景。 但是当我在genymotion中运行我的应用程序时,第一页的背景颜色是深灰色,我是Android开发的新手,所以我不知道如何处理它。 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>

主要活动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();     
}
}

任何人都可以帮助我吗?它可以通过转换来解决吗?

1 个答案:

答案 0 :(得分:0)

请参阅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);
                }
            });
}