【发布时间】:2014-08-12 19:29:53
【问题描述】:
我有一个带有渐变背景的 XML 布局页面。我还有一个动画 XML 页面来将 alpha 从 1 更改为 0,还有一个可绘制的 xml 页面来定义一个形状作为布局页面的背景。 我要做的是淡出背景,然后转到第二页。但是,该项目没有运行。
drawable/linegradiant.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>
动画/fade_out.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000" >
</alpha>
MainActivity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/firstpage"
android:background="@drawable/linergradiant"
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 implements AnimationListener {
LinearLayout screen;
// Handler handler = new Handler();
int i;
Intent intent;
Animation animFadeout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
screen=(LinearLayout) findViewById(R.id.firstpage);
animFadeout=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_out );
animFadeout.setAnimationListener(this);
screen.post(new Runnable() {
@Override
public void run() {
screen.startAnimation(animFadeout);
}
});
}
@Override
public void onAnimationEnd(Animation arg0) {
startActivity(new Intent(getApplicationContext(),BMIcalculator.class));
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
}
【问题讨论】:
-
“项目无法运行”是什么意思?是否抛出异常?如果是,请发布堆栈跟踪。
-
@Loop 我的意思是它不起作用并且没有错误。如果它有错误并且我无法解决它,我也把那个错误放在这里。
-
@mimi 你什么时候想改变活动??是动画完成的时候吗?
-
@Rod_Algonquin 是的。
标签: java android xml shape alpha