简体   繁体   中英

How to set Margin Left ,Margin top,Margin right and Margin Bottom alignment for popup window dynamically in android

I am currently doing an android application that contains a popup window named as mypopup. It contains a Image button and four textviews. i want to align the popup window dynamically with margin top,margin bottom,margin left and margin right parameters..In my code setmargin method is not working..please anybody help me to do this...

It depends that which layout you are using. Below example places a RelativeLayout in a 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM