Screen Size Honeycomb Menu android

时光毁灭记忆、已成空白 提交于 2019-12-02 00:12:49

问题


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 device but it is a super ugly hack. I am sure google people are not dumb enough to forget to give the user a function to get the height of the bottom menu bar so I can subtract it from the full screen size

This is a similar post. Size of android notification bar and title bar?

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

what_i_need =metrics.heightPixels-buttomMenuHeight();

I need buttomMenuHeight();

i could not find it in the API. I don't really care about the backward comparability at this point

Thanks


回答1:


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.




回答2:


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?)




回答3:


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.



来源:https://stackoverflow.com/questions/5173926/screen-size-honeycomb-menu-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!