1
我在ImageView中顯示了一個動畫GIF,並在其上顯示了一個透明背景TextView。我希望能夠根據動畫中顯示的當前幀動態更改TextView中的文本。有沒有一種機制可以做到這一點?Android - 如何顯示gif中的特定幀時通知我?
我在ImageView中顯示了一個動畫GIF,並在其上顯示了一個透明背景TextView。我希望能夠根據動畫中顯示的當前幀動態更改TextView中的文本。有沒有一種機制可以做到這一點?Android - 如何顯示gif中的特定幀時通知我?
我找到了答案。我實現了Drawable.ICallback,然後使用AnimationDrawable.GetFrame()來設置我需要的每一幀的回調。
private class MyFragment : DialogFragment, Drawable.ICallback
{
TextView tv; /* this is later defined in OnCreateDialog */
...
/* Must implement */
public void InvalidateDrawable(Drawable who)
{
/* As you can see in OnCreateDialog(), this gets called for
frames 0 and 56 */
if (iVocabIndex == 0) {
tv.Text = "Show this text";
iVocabIndex = 1;
}
else if (iVocabIndex == 1) {
tv.Text = "Show this other text";
iVocabIndex = 0;
}
}
/* Must implement */
public void ScheduleDrawable (Drawable who, IRunnable what, long when)
{
}
/* Must implement */
public void UnscheduleDrawable (Drawable who, IRunnable what)
{
}
public override Dialog OnCreateDialog (Bundle savedInstanceState)
{
ImageView image = view.FindViewById<ImageView> (Resource.Id.confDialogImage);
tv = view.FindViewById<TextView> (Resource.Id.confDialogImageText);
image.SetImageResource (Resource.Drawable.my_animation_xml);
AnimationDrawable b1Anim = (AnimationDrawable)image.Drawable;
b1Anim.Start();
Drawable d = b1Anim.GetFrame(0);
d.Callback = this;
d = b1Anim.GetFrame(56);
d.Callback = this;
}