以下是动画xml中的内容:
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="4500"
在这里我称之为:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
setContentView(R.layout.prayerlayout);
txt = (TextView) findViewById(R.id.textView2);
txt.setText(getString(R.string.eighth));
//apply animation
fade1 = AnimationUtils.loadAnimation(this, R.anim.fade10);
txt.startAnimation(fade1);
}
问题是文本在动画持续时间内没有显示,然后突然出现。在旧版本的android中我没有注意到这个问题。它工作得很好,但是使用Lollipop或Jellybeans它并不起作用。谢谢你的帮助。
答案 0 :(得分:1)
事实证明我的文字太长导致淡入动画无效。我在scrollView上应用了动画,它实现了我想要的效果。
答案 1 :(得分:0)
我在fadein XML中有这个。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
代码
public class MainActivity extends Activity {
Animation animFadein,animFadeout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_main);
animFadein = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
animFadeout = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
Update();
}
public void Update(){
TextView lblEstadoPuerta = (TextView) findViewById(R.id.lblEstadoPuerta);
ImageButton btnabrirpuerta = (ImageButton) findViewById(R.id.btndoorstate);
btnabrirpuerta.startAnimation(animFadeout);
btnabrirpuerta.setVisibility(View.GONE);
btnabrirpuerta.setImageResource(R.drawable.go_down);
btnabrirpuerta.setVisibility(View.VISIBLE);
btnabrirpuerta.startAnimation(animFadein);
}
}
需要导入此..
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
答案 2 :(得分:0)
你添加了一些内插器吗?
你可以读到这个:
http://developer.android.com/intl/es/guide/topics/resources/animation-resource.html
您的fade10.xml动画文件
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="4500"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
您的活动文件
public class FadeActivity extends Activity {
private TextView txt;
private Animation fade1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prayerlayout);
txt = (TextView) findViewById(R.id.textView2);
txt.setText(getString(R.string.eighth));
//apply animation
fade1 = AnimationUtils.loadAnimation(this, R.anim.fade10);
txt.startAnimation(fade1);
}
}