để thêm vào câu trả lời eboix ... đây là cách tôi mờ dần trong văn bản và mờ dần văn bản, với độ trễ giữa mỗi phai và trước khi mờ dần, (nghĩa là ngay sau khi mờ dần).
XML của tôi trông như thế này.
<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>
Các bạn sử dụng các biến này trong các hoạt động của bạn/mảnh/dialogfragment, sau đây là các biến tôi được sử dụng trong tôi ...
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[]{""};
Bây giờ các đối tượng và các biến được innitialized là được sử dụng như thế này, tôi đã sử dụng nó cho đoạn hộp thoại của mình, trong phương thức 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);
Tuyệt vời câu trả lời! :) –
@eboxis Cảm ơn bạn đã chia sẻ kiến thức..vì có cách nào để thực hiện hoạt ảnh theo trình tự cho nhiều lượt xem .. Tôi đã thử bắt đầu hoạt ảnh cho chế độ xem thứ hai trong hoạt ảnhEnd của chế độ xem đầu tiên ... nhưng khi tôi làm điều đó .. .first xem lại hoạt ảnh ... bất kỳ đề xuất nào ...? – CoDe
Tuyệt vời! Cách tiếp cận thứ hai đã làm cho các trick cho tôi! Cảm ơn :) –