android - Left margin is not working from java -
i adding image , giving margin left using below code.
layoutparams.setmargins(translateby, 0, 0, marginbottom); slideicon.setlayoutparams(layoutparams);
this code working devices of different density , size.
but not working device properties :- 540x960, 240dpi, 4.7 inch device
but if give margin .xml file working.
please me on this.
thanks in advance.
you can use displaymetrics logic
a structure describing general information display, such size, density, , font scaling.
displaymetrics metrics = getresources().getdisplaymetrics(); int devicetotalwidth = metrics.widthpixels; int devicetotalheight = metrics.heightpixels; layoutparams.setmargins(devicetotalwidth/8, 0, 0, marginbottom); // left, top, right, bottom // devicetotalwidth/8 set yours left margin
edited
@courtesy goes #stanojkovic
layoutparams params = new layoutparams( layoutparams.wrap_content, layoutparams.wrap_content ); params.setmargins(left, top, right, bottom);
hope helps .
Comments
Post a Comment