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;
}