当前我有一个dialog
,该图像显示了用户正在单击的图像。
我想做的是在button
的{{1}}上添加一个bottom
。
这是我当前的代码:
dialog
当前代码为:
public void showImage(Drawable drawable) {
final Dialog builder = new Dialog(mContext);
builder.setCancelable(true);
builder.setCanceledOnTouchOutside(true);
builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
builder.getWindow().setBackgroundDrawable(
new ColorDrawable(Color.RED));
// builder.getWindow().setBackgroundDrawable(
// new ColorDrawable(android.graphics.Color.TRANSPARENT));
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//nothing;
}
});
ImageView imageView = new ImageView(mContext);
Button mClose = new Button(mContext);
mClose.setText("CLOSE");
mClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
builder.dismiss();
}
});
imageView.setImageDrawable(drawable);
builder.addContentView(imageView, new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
builder.addContentView(mClose,new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
builder.show();
}
在button
的左上方,应该在imageview
的下方。
答案 0 :(得分:1)
尝试一下
之后
builder.addContentView(mClose,new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
添加此内容
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// yourButton
builder.addContentView(yourButton,lp));
答案 1 :(得分:0)
更好地创建自己的自定义对话框并显示图像和按钮。
请查看下面的类似链接,这可能会对您有所帮助。
How to make a pop up image like an advertisement? [Android]
Show AlertDialog with ImageView without any padding
谢谢