要添加到eboix答案...這就是我淡入文本和淡出文本,每次淡入和淡出之間的延遲(即淡入之後)。
我的XML看起來像這樣。
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Retrieving Result"
android:textColor="@color/general_app_colour"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/blobText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Please Wait" />
</LinearLayout>
的你在活動/片段/ dialogfragment使用這個變量,下面是我在我使用的變量...
public class Loading_Dialog extends DialogFragment {
public String[] text = new String[]{""};
TextView blobText;
Animation inAnimation;
Animation displayLength;
Animation delayAnimation;
Animation outAnimation;
//duration for fade effects
int fadeEffectDuration = 700;
//duration for delay between fadeout and fadein
int delayDuration = 1000;
int displayFor = 2000;
public String[] text = new String[]{""};
現在的對象和變量innitialized是像這樣使用,我用這個我的對話框片段,在oncreateDialog方法..
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity(),R.style.LoadingDialogAnimation);
dialog.getWindow().setContentView(R.layout.dialog_loading);
blobText = (TextView) dialog.findViewById(R.id.blobText);
inAnimation = new AlphaAnimation(0f, 1f);
inAnimation.setDuration(fadeEffectDuration);
displayLength = new AlphaAnimation(1f, 1f);
displayLength.setDuration(displayFor);
delayAnimation = new AlphaAnimation(0f, 0f);
delayAnimation.setDuration(delayDuration);
outAnimation = new AlphaAnimation(1f, 0f);
outAnimation.setDuration(fadeEffectDuration);
inAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
position++;
if(position>=text.length)
{
position = 0;
}
blobText.setText(text[position]);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
blobText.startAnimation(displayLength);
}
});
displayLength.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
blobText.startAnimation(outAnimation);
}
});
outAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
blobText.startAnimation(delayAnimation);
}
});
delayAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
blobText.startAnimation(inAnimation);
}
});
blobText.startAnimation(outAnimation);
出色答卷! :) – 2011-12-24 23:04:33
@eboxis感謝您的知識分享..有沒有什麼辦法按順序執行多個視圖的動畫..我試着用第一個視圖的animationEnd中的第二個視圖開始動畫...但是當我這樣做時.. .first視圖再次獲得動畫...任何建議...? – CoDe 2014-02-17 13:41:48
令人驚歎!第二種方法爲我做了詭計!謝謝:) – 2016-03-02 07:05:09