1

I have a RelativeLayout with height parameter match_parent and in this I have another LinearLayout with property layout_alignParentBottom=true.

I am using this layout to show MediaController buttons.

Below is what I am expecting to have in MediaController

enter image description here

But below is what I am getting on Lollipop 5.1 (I have just added hard coded bottom margin to the layout, which is not at all any solution as it will not work well on all devices.)

enter image description here

The layout hides behind the bottom back button bar.

What will be the best way to only provide the necessary margin from bottom according to height of bottom bar as this layout works fine in other Android versions and earlier Android phones with Hardware back buttons.

My XML file looks like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mypack.MyActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottomLinear"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/albumArt"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_gravity="center"
            android:background="@drawable/default_cover" />

        <TextView
            android:id="@+id/titleOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Title Of Song"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/albumOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Album Of Song"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/artistOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Artist Of Song"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/genreOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Genre Of Song"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >
    </LinearLayout>

</RelativeLayout>

App Theme

<style name="AppBaseTheme" parent="Theme.AppCompat"></style>
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowAnimationStyle">@null</item>
</style>
gprathour
  • 14,813
  • 5
  • 66
  • 90
  • This doesn't really make sense, the button bar isn't part of the normal screen, and align parent bottom isnt affected by this. Are you sure you don't have a negative bottom margin or similar? Or maybe the container over the player is pushing it out of the screen? – breakline Jun 28 '15 at 12:47
  • @breakline Well these days I am facing issues that are weird. Yes I am sure No negative margin or similar. I have posted my XML file. – gprathour Jun 28 '15 at 12:49
  • Did you try layout_gravity -> center? Btw post the complete xml with the all components, its easier to analyse the your problem. – Xplouder Jun 28 '15 at 13:05
  • @Xplouder I posted the complete XML file. Gravity Center? Why I need to show it at bottom. – gprathour Jun 28 '15 at 13:08
  • Did you find a solution? – Angie Jul 17 '15 at 14:44
  • @Angie Nopes. Just have provided hard coded margin bottom till now. If I get a solution I will post it here. If you get you post it here. – gprathour Jul 19 '15 at 03:30

5 Answers5

0

It seems that your Activity is somehow using transparent navigation bar theme or something similar that allows to render view outside of the visible area.

Maybe giving some context about your Activity will help to figure out what is exactly happening.

That being said, you should use this attribute android:fitsSystemWindows in the root of your XML layout to force views to render only in the visible area of the window.

Simon Marquis
  • 7,248
  • 1
  • 28
  • 43
  • 1
    I just added `context` in XML mentioned in question. Also I tried to give `android:fitsSystemWindows="true"` to root element but no luck. – gprathour Jun 28 '15 at 13:47
  • @gprathour I wasn't talking about `tools:context` but the style/theme/configuration of the Activity holding this view (`MyActivity`) – Simon Marquis Jun 28 '15 at 14:04
  • Just added theme of application to question. Is it what you asked for? – gprathour Jun 28 '15 at 14:09
  • Yes, but the Activity configuration would be a plus. Are you setting visibility flags to the Activity decor view ? Or doing things like https://developer.android.com/training/system-ui/navigation.html ? – Simon Marquis Jun 28 '15 at 14:15
  • I have just added `requestWindowFeature(Window.FEATURE_NO_TITLE);` apart from it nothing like that. Where can I find Activity Configuration ? – gprathour Jun 28 '15 at 14:23
0

If you want to keep everything else the same and just add a bottom margin, this answer describes a way to get the height of the bottom soft key bar by subtracting getRealMetrics() and getMetrics() and using the difference to imply the height dimension.

Not tested the method myself, but the feedback seems positive.

Community
  • 1
  • 1
MattMatt
  • 2,242
  • 33
  • 30
  • 1
    Hmm.. Thanks. I have gone through such options but was wondering if we could find out why such thing is happening and any genuine way to solve this issue, not just a hack. – gprathour Jun 28 '15 at 13:54
  • Apologies, I missed the line where you said that you'd hard-coded the margin already. Could you share the styles that you're using? As it feels to me like it's behaving in the same way as overlay mode for the action bar, just on the bottom. There may be a clue as to why in there. – MattMatt Jun 28 '15 at 14:08
0

You can use the defaultDisplay height and width in your Layout like this : For you it's RelativeLayout params.

    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) yourUI.getLayoutParams();
    params.width = metrics.widthPixels;
    params.height = metrics.heightPixels;
    params.leftMargin = 0;
    yourUI.setLayoutParams(params);
Angie
  • 277
  • 1
  • 7
0

I solved this problem by setting programmatically the layout height equals the display height.

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
      statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
RelativeLayout relativeLayout =(RelativeLayout)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)relativeLayout.getLayoutParams();
lp.height = height - statusBarHeight;
relativeLayout.setLayoutParams(lp);
Mikhail
  • 1
  • 1
0

Hi @gprathour try this

<LinearLayout
        android:id="@+id/bottomLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="?attr/actionBarSize"
        android:orientation="horizontal" >
    </LinearLayout>

Hope this helps.

mdb
  • 166
  • 8