[ View height incorrectly measured Android 5+ ]

I've created fragment that is shown by reside menu (https://github.com/SpecialCyCi/AndroidResideMenu) as content for some menu item. The problem is that on Android 5+ height of ExpandableListView (green frame) is not measured correctly it cuts off bottom strip (approximately height) of system navigation buttons that are below. Looks like scroll frame is under those buttons and I can't scroll to show this part.

Incorrectly measured ExpandableListView

Now. After many tries I got the views to be almost correctly measured. I've added in onCreateView of my fragment:

if(Build.VERSION.SDK_INT >= 21) {
    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}

ExpandableListView doesn't go under system buttons, but I have blank space on the top of view. Unfortunately this blank space stays there even if I switch menu item.

Can anyone share ideas what might be wrong?

Blank space on the top

Answer 1


I have encountered this problem too. (Android ResideMenu library, bottom of Fragment has Cropping issue) As you said View height incorrectly measured on Lollipop devices. I found partial solution for it. While I'm trying to give transparency to the native navigation bar, I set android:windowTranslucentNavigation true in my values-v21 folder. Then View height started to calculate correctly, but color of the navigation bar has changed.

<resources>
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="android:actionBarStyle">@style/Widget.AppCompat.ActionBar</item>

     <item name="android:windowTranslucentNavigation">true</item>

        </style>
</resources>

Answer 2


Hi there after around one week of work I found the perfect solution.

Main Activity

protected void onCreate(Bundle savedInstanceState)

{
etWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
mToolbar = (Toolbar) findViewById(R.id.toolbar);

((LinearLayout.LayoutParams)

mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);

}

public static int getStatusBarHeight(Context context) {
    int result = 0;
    int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = context.getResources().getDimensionPixelSize(resourceId);
    }
    return result;
}

AndroidManifest activity add this line

<activity
            android:name=".activity.Main"
            android:configChanges="orientation|screenSize"
             android:windowSoftInputMode="adjustPan"
             android:fitsSystemWindows="true"
               android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

styleV21

<style name="myTheme" parent="FridayfairTheme.Base">
      <item name="android:windowTranslucentNavigation">true</item>
</style>