我试图创建一个自定义对话框,其中包含主要的LinearLayout,其中包含2个嵌套的LinearLayout,其中包含ImageView和TextView。
但问题是没有LinearLayout出现。我甚至没有收到任何错误,应用程序也没有崩溃。
谢谢。
以下是与此问题相关的代码段:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ll_main = new LinearLayout(AddFreebie.this);
ll_main.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ll_main.setGravity(Gravity.CENTER);
ll_main.setOrientation(LinearLayout.VERTICAL);
ll_bpic = new LinearLayout(AddFreebie.this);
ll_bpic.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ll_bpic.setGravity(Gravity.CENTER);
ll_bpic.setOrientation(LinearLayout.HORIZONTAL);
iv_bpic = new ImageView(AddFreebie.this);
iv_bpic.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tv_bpic = new TextView(AddFreebie.this);
tv_bpic.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tv_bpic.setText("Browse phone for pictures..");
ll_bpic.addView(iv_bpic);
ll_bpic.addView(tv_bpic);
ll_cpic = new LinearLayout(AddFreebie.this);
ll_cpic.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ll_cpic.setGravity(Gravity.CENTER);
ll_cpic.setOrientation(LinearLayout.HORIZONTAL);
iv_cpic = new ImageView(AddFreebie.this);
iv_cpic.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tv_cpic = new TextView(AddFreebie.this);
tv_cpic.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tv_cpic.setText("Take pictures using camera.");
ll_cpic.addView(iv_cpic);
ll_cpic.addView(tv_cpic);
ll_main.addView(ll_bpic);
ll_main.addView(ll_cpic);
builder.setView(ll_main);
builder.setCancelable(true);
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// MyActivity.this.finish();
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
答案 0 :(得分:2)
我可能不对,但我不认为在这种情况下你真的想要使用AlertDialog。如果您阅读AlertDialogs上的Developer页面,它们实际上可用于小型0,1,2或3个按钮警报窗口,并不是真正意味着拥有自己真正的自定义界面。以下是AlertDialogs
的一些链接http://www.helloandroid.com/tutorials/how-display-alertdialog-your-android-application
要做你想做的事情,我想你要么想要使用Diaglog,要么使用PopupWindow
创建自定义对话框的链接: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
创建自定义弹出窗口的链接(我以前使用过这些窗口): http://www.mobilemancer.com/2011/01/08/popup-window-in-android/