0

I am working on a feature in my app where I need to know the exact height of the parent view. But apparently this value is wrong on some devices (e.g. my Huawei P8 lite).

I realized it was wrong when I tried drawing something at point (x, view.getheight), where the point didn't show up at the bottom, but rather near the middle of the screen. This was not the case on my Google Nexus.

Here is the snippet of code where the 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 to display empty state onboarding");
            }
        });

For the record, the class called OverlayBuilder is a builder class, used for drawing different things on the screen at runtime. In the case I am drawing an arrow between 2 points, but both the beginning and the end of the line/arrow is completely wrong on my Huawei P8.

I suspect that getHeight() returns dp in some cases, and in px on my Google Nexus. If this could be the case, how can this be fixed properly? The variable parentHeight, is the one that contains the wrong height.

halfer
  • 19,824
  • 17
  • 99
  • 186
Langkiller
  • 3,377
  • 13
  • 43
  • 72
  • `getHeight` is deprecated. http://stackoverflow.com/a/19639744/5885018 – statosdotcom Jul 11 '16 at 13:05
  • `getHeight` for display metrices is depricated, that's not being used here i think, as in the docs : https://developer.android.com/reference/android/view/Display.html#getHeight() – Ashish Ranjan Jul 11 '16 at 13:09
  • @user68621 : for which view are you getting the wrong values? – Ashish Ranjan Jul 11 '16 at 13:16
  • Pixel value differs from device to device – Akshay Bhat 'AB' Jul 11 '16 at 13:22
  • @AkshayBhat Yes I am aware of that :) But when I try to draw my line with the height as the second "y" value, it is not placed at the bottom on my Huawei, like on the other devices. – Langkiller Jul 11 '16 at 13:48
  • Maybe I have misunderstood where the problem lies.. I actually think it is the drawing part that acts weird on my Huawei device. Sorry if I have wasted your time. I will put some time into researching it further. Thanks so far. – Langkiller Jul 11 '16 at 13:55

0 Answers0