4

I'm having troubles with layouts being too large on Devices with Soft-Key-Buttons on Android:

Summing up, my question is why a layout, which is configured as "match_parent" has its View-bounds extended to the "real" bottom window bound, instead of just above the Soft-Key-Buttons?

Now to my specific problem:

While displaying a RelativeLayout (in a Fragment, if thats necessary to know) with a View layout_alignParentBottom="true" on any Device with Soft-Key-Buttons, the View is displayed "behind" the Soft-Key-Buttons.

Image of the View on a Device without Soft-Key-Buttons (as it should be)

Image of the View on a Device with Soft-Key-Buttons (the Button is "hiding" behind the Soft-Keys)

The RelativeLayout looks like this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg2">

    <LinearLayout
        android:layout_marginTop="@dimen/settings_container_margin_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

        <!-- Some views -->

    </LinearLayout>

    <at.eventdrivers.android.ui.MenuButton
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:layout_gravity="center_horizontal"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        custom:btnText="@string/..." />

</RelativeLayout>

As I'm quite new to Android Development and also have not done anything before with Fragments, the error could also be in the fragment-management, so I'm going to post this too:

The Activity, in which the fragment is shown, is configured in the AndroidManifest:

<activity
    android:name=".slidingmenu.SlidingHomeActivity"
    android:label="@string/app_name"
    android:logo="@mipmap/ic_launcher"
    android:theme="@style/AppBaseTheme"
    android:windowSoftInputMode="adjustResize"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

The used FrameLayouts all have layout_width and layout_height set to match_parent.

Right now I'm using kind of a workaround with programmatically checking if the device is showing Soft-Key-Buttons, and if yes, setting the margin of this Button to a higher value:

public static boolean hasSoftKeys(Context c) {
    if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&
            ViewConfiguration.get(c).hasPermanentMenuKey())) {
        //menu key is present
        return false;
    } else {
        //No menu key
        return true;
    }
}

The problem there is, that the Soft-Key-Buttons have a different height on different devices, so I would have to check the height of the Soft-Key-Buttons too (which is possible and already answered on StackOverflow).

I'm stuck at this problem for a few weeks now and would really appreciate any help.

Florian Mötz
  • 115
  • 2
  • 6

2 Answers2

4

This one worked for me, just add it to your v21/styles.xml

<item name="android:windowDrawsSystemBarBackgrounds">false</item>
Analizer
  • 1,594
  • 16
  • 30
2

I can imagine three different scenarios:

  1. (Unlikely)You do something with LayoutParams Flags of your Window(like getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);) and/or Theme's styles

  2. (Unlikely. It was my initial though, but layout_alignParentBottom="true" should handle it for you)You don't have enough space on the screen. Can you wrap your RelativeLayout into a ScrollView(it'd require you to change RelativeLayout's height to wrap_content) and see the result? (If you set match_parent to the RelativeLayout it does not mean it'd fit all content into the screen sizes. Content can easily get out of the screen, like on the screenshot you provided. But again, layout_alignParentBottom="true" handles it.

  3. (Most likely) You have some margins/paddings in the Activity(especially, something like android:layout_marginBottom="-XXdp"), which hosts Fragment. So fragment is rendering correctly, but the Activity moves it below the screen.

To speak more precisely, it'd be nice to have @style/AppBaseTheme here, Activity's layout and if you do something suspicious with getWindow() - this piece of code.

Let me know, if it helps or not!

Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
  • 1
    I've checked all your 3 scenarios and the only time I'm using **getWindow()** in a way, it could interfere with the fragment/activity, is in the jfeinstein10's [SlidingMenu-Library](https://github.com/jfeinstein10/SlidingMenu). There it is used if the mode SLIDING_WINDOW is selected. This probably changes some parameters so the soft-keys are "hiding" some content (or i'm just doing it wrong). **To sum up**, changing the Sliding-Menu's mode to **SLIDING_CONTENT** solves my problem. So thank you for your quick and very detailed answer! – Florian Mötz Jan 07 '16 at 17:41
  • @FlorianMötz I have same issue with sliding menu but i have changed mode to SLIDNG_CONTENT doest not solve my issue can you please help me – PriyankaChauhan Jun 23 '17 at 08:03
  • @PriyankaChauhan Did u solve urs problem , i have stucked in the same problem yet..Please help me on it – Ravindra Kushwaha Sep 07 '17 at 13:02
  • @RavindraKushwaha I had solved issue by adding some code in SlidingMenu.java – PriyankaChauhan Sep 07 '17 at 14:03
  • @PriyankaChauhan CAn u plz share it – Ravindra Kushwaha Sep 07 '17 at 14:05
  • check this link https://github.com/jfeinstein10/SlidingMenu/issues/680 and find anwer form "Den-Rimus" – PriyankaChauhan Sep 07 '17 at 14:05
  • @PriyankaChauhan It resolve the issue but it is occurring the white gap on other devices.New issue generated :P – Ravindra Kushwaha Sep 07 '17 at 14:17
  • public boolean isNavigationBarAvailable() { boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME); return (!(hasBackKey && hasHomeKey)); } add this function – PriyankaChauhan Sep 08 '17 at 05:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153919/discussion-between-priyankachauhan-and-ravindra-kushwaha). – PriyankaChauhan Sep 08 '17 at 05:28