4

我想在警报框中播放 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
}


}

但不能。

4

1 回答 1

2

确保 imageButton1 设置为 activity_fruits 布局 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");
        }

    });
于 2013-10-30T06:13:06.643 回答