Screen Size Honeycomb Menu android

前端 未结 3 1728
囚心锁ツ
囚心锁ツ 2021-01-20 03:06

Hi I am trying yo get the screen size of screen minus the menu bar at the bottom.

I know I could just subtract a constant number according to the resolution of the d

相关标签:
3条回答
  • 2021-01-20 03:45

    I am drawing image in native code and I need to pass the size of the screen to C.

    I tried to get the Height by getHeight() of the view but that returns 0 always even after setContentView is called.

    RelativeLayout masterLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
    masterLayout.setLayoutParams(params);
    setContentView(masterLayout);
    

    when I try masterLayout.getHeight(), it returns 0. I expected to get the full screen height as I said fill_parent.

    0 讨论(0)
  • 2021-01-20 03:53

    Try calling getHeight() after onLayout. The view is not sized on inflate.

    EDIT: Or since Activity does not have onLayout you might wait for onSizeChanged.

    (Reference How to know when activity is laid out?)

    0 讨论(0)
  • 2021-01-20 03:58

    Why not use the height of the activity's top-level View? e.g. if your activity contains a full-height LinearLayout, use its height, so you don't have to know the menu height, or noticiation bar height.

    I think you're treading a dangerous road doing this kind of calculation, as you don't know what the future layouts for Android might be, or how they might differ on Google TV, or whatever.

    0 讨论(0)
提交回复
热议问题