我试图创建一个自定义对话框,其中包含主要的 LinearLayout,其中有 2 个嵌套的 LinearLayout,其中包含 ImageView 和 TextView。
但问题是没有出现任何线性布局。我什至没有收到任何错误,应用程序也没有崩溃。
谢谢你。
以下是与此问题相关的代码段:
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();