Подтвердить что ты не робот

Мигающий текст в представлении android

Как отобразить Мигающий текст в андроиде.

Спасибо всем.

4b9b3361

Ответ 1

Вы можете использовать это:

TextView myText = (TextView) findViewById(R.id.myText );

Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
myText.startAnimation(anim);

Надеюсь, это поможет!

Ответ 2

На самом деле в ICS есть мигающий значок пасхального яйца!:) Я на самом деле не рекомендую его использовать - было ДЕЙСТВИТЕЛЬНО забавляться, чтобы найти его в источнике, хотя!

<blink xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I'm blinking"
        />
</blink>

Ответ 3

Создайте для него анимацию вида. Вы можете сделать альфа-затухание от 100% до 0% за 0 секунд и обратно в цикле. Таким образом, Android обрабатывает его интеллектуально, и вам не нужно возиться с потоками и ненужным процессором.

Подробнее о анимации здесь:
http://developer.android.com/reference/android/view/animation/package-summary.html

Учебник:
http://developerlife.com/tutorials/?p=343

Ответ 4

Это можно сделать, добавив ViewFlipper, который чередует две анимации TextViews и Fadein и Fadeout, которые могут применяться при их переключении.

Файл макета:

<ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="wrap_content" android:flipInterval="1000" >

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="TEXT THAT WILL BLINK"/>

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="" />

</ViewFlipper>

Код действия:

private ViewFlipper mFlipper;
mFlipper = ((ViewFlipper)findViewById(R.id.flipper));
mFlipper.startFlipping();
mFlipper.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));

Ответ 5

Использование потоков в вашем коде всегда тратит процессорное время и снижает производительность приложения. Вы не должны использовать потоки все время. Используйте, если необходимо.

Используйте XML-анимации для этой цели:

R.anim.blink

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="600"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>

Активность blink: используйте его следующим образом: -

public class BlinkActivity extends Activity implements AnimationListener {

    TextView txtMessage;
    Button btnStart;

    // Animation
    Animation animBlink;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blink);

        txtMessage = (TextView) findViewById(R.id.txtMessage);
        btnStart = (Button) findViewById(R.id.btnStart);

        // load the animation
        animBlink = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.blink);

        // set animation listener
        animBlink.setAnimationListener(this);

        // button click event
        btnStart.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                txtMessage.setVisibility(View.VISIBLE);

                // start the animation
                txtMessage.startAnimation(animBlink);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        // Take any action after completing the animation

        // check for blink animation
        if (animation == animBlink) {
        }

    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }

    @Override
    public void onAnimationStart(Animation animation) {

    }

}

Сообщите мне, есть ли у вас какие-либо вопросы.

Ответ 6

If you want to make text blink on canvas in bitmap image so you can use this code
we have to create two methods 
So first, let declare a blink duration and a holder for our last update time: 
private static final  int BLINK_DURATION = 350; // 350 ms
private long lastUpdateTime = 0; private long blinkStart=0;

теперь создайте метод

    public void render(Canvas canvas) {
    Paint paint = new Paint();
    paint.setTextSize(40);
    paint.setColor(Color.RED);
    canvas.drawBitmap(back, width / 2 - back.getWidth() / 2, height / 2
            - back.getHeight() / 2, null);
    if (blink)
        canvas.drawText(blinkText, width / 2, height / 2, paint);
}

Теперь создайте метод обновления, чтобы мигать

public void update() {
if (System.currentTimeMillis() - lastUpdateTime >= BLINK_DURATION
        && !blink) {
    blink = true;
    blinkStart = System.currentTimeMillis();
}
if (System.currentTimeMillis() - blinkStart >= 150 && blink) {
    blink = false;
    lastUpdateTime = System.currentTimeMillis();
 }

}

Теперь он отлично работает