android动画无效

时间:2014-02-04 14:24:16

标签: android animation android-animation

我正在尝试使用简单的淡入淡出来制作图像视图的动画,但是当我在我的模拟器中运行它时它什么都不做。知道发生了什么或我做错了什么? 我试图在这个website中重现这个例子,但不知何故它不起作用。

以下是我的XML示例:

<?xml version="1.0" encoding="utf-8"?>
<set 
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:interpolator="@android:anim/accelerate_interpolator">
    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:duration="2000"
    >
    </alpha>
</set>

以下是我的代码示例:

protected void onStart () 
    {
        super.onStart();



    RelativeLayout layout = (RelativeLayout) findViewById(R.id.relative);
    ImageView logo = new ImageView(this);

    int margem_px = 50;
    float density = this.getResources().getDisplayMetrics().density;
    int margem_dp = (int)(density*margem_px);

    Resources res = getResources();
    layout.setBackgroundColor(res.getColor(R.color.branco));


    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(margem_dp, margem_dp*2, margem_dp, margem_dp);
    logo.setLayoutParams(params);



    logo.setImageResource(R.drawable.pc_apps_logo_white);

    logo.setScaleType(ScaleType.CENTER_INSIDE);
    logo.setVisibility(View.VISIBLE);
    logo.setAlpha((float) 0);

    layout.addView(logo);




  Animation anima = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myfadein);
    logo.startAnimation(anima);


  } 
}

1 个答案:

答案 0 :(得分:0)

只需删除此行&amp;你走了:

logo.setAlpha((float) 0);
相关问题