[英]How to set Margin Left ,Margin top,Margin right and Margin Bottom alignment for popup window dynamically in android
我目前正在做一个包含名为mypopup的弹出窗口的android应用程序。 它包含一个图像按钮和四个文本视图。 我想用上边距,下边距,左边距和右边距右边的参数动态对齐弹出窗口。
这取决于您使用的布局。 下面的示例将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);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0,0, 5, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.