I have an activity containing a RecyclerView and both transparent status bar (the one containing wifi signal, etc...) and softkeys bar. Of course the number of items in the RecyclerView is undefined and i need the first one to have the standard top margin plus the status bar height, and the last one the standard bottom margin plus the height of the softkeys bar. This is needed because otherwise i'll get the first and the last items partially covered by the bars when the scroll is at the top or at the bottom respectively.
Here a sample code of how i'm handling the margins programmatically:
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
topSpace = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
bottomSpace = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
standardSpace = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
topSpace.setMargins( (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8 + 24, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics));
bottomSpace.setMargins( (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8 + 56, metrics) +
getSoftkeysHeight(activity));
standardSpace.setMargins((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics),
(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics));
I'm trying to use those answers but they seems not helping me because the drawable surface of the screen is indeed the whole screen...