[英]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.