我目前正在做一个包含名为mypopup的弹出窗口的Android应用程序。它包含一个图像按钮和四个文本视图。我想动态地将弹出窗口与边距顶部,边距底部,边距左边和边距右边的参数对齐。在我的代码中,setmargin方法无法正常工作..请任何人帮我这样做...
答案 0 :(得分:0)
这取决于您使用的是哪种布局。下面的示例将RelativeLayout放在LinearLayout中。
LinearLayout linearLayoutParent;
RelativeLayout relativeLayout;
RelativeLayout.LayoutParams margin = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
margin.setMargins(0, 0, 0, 7); //7px bottom margin
//create the linear and the relative layouts
//...add other stuff here...
// Add view with its margins
linearLayoutParent.addView(relativeLayout, margin);
答案 1 :(得分:-1)
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0,0, 5, 0);