1

我目前正在做一个包含名为 mypopup 的弹出窗口的 android 应用程序。它包含一个图像按钮和四个文本视图。我想将弹出窗口与上边距、下边距、左边距和右边距参数动态对齐..在我的代码中 setmargin 方法不起作用..请任何人帮我这样做...

4

2 回答 2

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);
于 2013-07-24T06:06:16.037 回答
-1
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0,0, 5, 0);
于 2013-07-24T06:03:57.363 回答