Android view getheight() returns wrong px value on some devices -
i working on feature in app need know exact height of parent view. apparently value wrong on devices (e.g. huawei p8 lite).
i realized wrong when tried drawing @ point (x, view.getheight), point didn't show @ bottom, rather near middle of screen. not case on google nexus.
here snippet of code problem lies:
final overlaybuilder builder = new overlaybuilder(context, parentview, tag); builder.setonlayoutlistener(new servicecallback<overlaybuilder.overlayrelativelayout>() { @override public void onsuccess(overlaybuilder.overlayrelativelayout overlaylayout) { viewgroup.marginlayoutparams lp = (viewgroup.marginlayoutparams) createagentbtn.getlayoutparams(); linearlayout childcontainer = overlaylayout.getchildcontainer(); int parentheight = parentview.getheight(); view iconview = childcontainer.getchildat(0); view textview = childcontainer.getchildat(1); int nocontentviewheight = iconview.getheight() + textview.getheight(); int btnheight = createagentbtn.getheight() + lp.topmargin + lp.bottommargin; int bottomoffset = ((parentheight - btnheight) / 2) - (nocontentviewheight / 2); int astarty = bottomoffset + nocontentviewheight; int aendy = parentheight - btnheight; arraylist<integer> layoutrules = new arraylist<>(relativelayout.align_parent_bottom); builder.setgroupparams(layoutrules, relativelayout.layoutparams.match_parent, relativelayout.layoutparams.wrap_content, 0, bottomoffset, linearlayout.vertical) .drawcurvedarrow(300, astarty, 300, aendy, -225, r.color.turtle_green, overlaybuilder.standard_linesize, overlaybuilder.standard_arrowsize).layout().commit(); } @override public void onfail(throwable t) { log.e(tag, "failed display empty state onboarding"); } });
for record, class called overlaybuilder builder class, used drawing different things on screen @ runtime. in case drawing arrow between 2 points, both beginning , end of line/arrow wrong on huawei p8.
i suspect getheight() returns dp in cases.. , in px on google nexus. if case, how can fixed properly? variable parentheight, 1 contains wrong height.
any appreciated.
Comments
Post a Comment