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.
I can imagine three different scenarios:
(Unlikely)You do something with
LayoutParams
Flags of yourWindow
(likegetWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
) and/or Theme's styles(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 yourRelativeLayout
into aScrollView
(it'd require you to changeRelativeLayout
's height towrap_content
) and see the result? (If you setmatch_parent
to theRelativeLayout
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.(Most likely) You have some margins/paddings in the
Activity
(especially, something likeandroid:layout_marginBottom="-XXdp"
), which hostsFragment
. 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 withgetWindow()
- this piece of code.Let me know, if it helps or not!
This one worked for me, just add it to your v21/styles.xml