在警报框中播放gif动画

时间:2013-10-30 05:12:49

标签: android gif

我想在警告框中播放gif动画。我正在尝试使用

构建
public class Fruits extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fruits);

    ImageButton apple = (ImageButton)findViewById(R.id.imageButton1);
    apple.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(Fruits.this);
            GIFWebView view = new GIFWebView(this, "file:///android_asset/apple.gif");
            setContentView(view);
            builder.create().show();
        }

    });

}

GIFWebView类

public class GIFWebView extends WebView {

public GIFWebView(Context context, String path) {
    super(context);
    loadUrl(path);
    // TODO Auto-generated constructor stub
}


}

但无法。

1 个答案:

答案 0 :(得分:2)

确保将imageButton1设置为activity_fruits layout xml中的ImageButton的android:id

请将代码更新为以下内容:

apple.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(TestKeyboard.this);
            WebView view = new WebView(Fruits.this);
            view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            builder.setView(view);
            builder.create().show();
            view.loadUrl("file:///android_asset/apple.gif");
        }

    });