简体   繁体   中英

Android Lollipop LinearLayout on the bottom of the screen

I have this problem only on Lollipop, older versions work (4.0 to 4.X).

In my xml, i have 3 parts :

  • First part : An ImageView with TextView.
  • Second part : A ListView
  • Third : A bottom bar with Buttons in a LinearLayout (horizontal)

Problem : In Android Lollipop Device, the third part is missing and ListView go to end of the screen.

Theme used : Theme.AppCompat.Light.NoActionBar (to colorize the MediaRouteButton in grey)

XML Code :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

            <ImageView
                android:id="@+id/cover"
                android:layout_width="match_parent"
                android:layout_height="@dimen/cover"
                android:layout_marginTop="0dp"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/default_cover" />

            And other stuff...

    </LinearLayout>

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_weight="1"
        android:clipToPadding="false"
        android:divider="@android:color/transparent"
        android:dividerHeight="15.0sp"
        android:paddingBottom="15dp"
        android:paddingTop="15dp"
        android:scrollbars="none" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#f0f0f0"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingBottom="5dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingTop="5dp"
            android:weightSum="10">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left">

                <ImageView
                    android:id="@+id/imageView4"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:src="@drawable/img1" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="10"
                android:gravity="center">

                <SeekBar
                    android:id="@+id/bar_vol"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="0dp"
                    android:layout_marginRight="5dp" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right">

                <ImageView
                    android:id="@+id/imageView5"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:src="@drawable/img2" />

                <android.support.v7.app.MediaRouteButton
                    android:id="@+id/media_route_menu_item"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_marginLeft="10dp"
                    android:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
                    android:background="@android:color/transparent"
                    android:showAsAction="always"
                    android:title="Cast" />

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>
</RelativeLayout>

Do you have an idea of where the problem is ?

In the bottom LinearLayout where android:weightSum="10" , this is the sum of all the android:layout_weight of the children UI elements. So...one LinearLayout (that contains SeekBar) has all the weight layout_weight="10" . This could impact the other UI elements and make them not visible.

Another, the parent layout with the weightSum is horizontal (android :orientation="horizontal" ), this means the children should have android :layout_width="0dp" . Otherwise they are conflicting with unpredictable results. It's like if you want to get benefits of weight calculations (and I like it too), don't specify the size too.

Depending on how things progress with my day, this post, and your response, I might download your layout xml for me to experiment. I plan to get a Master degree on layouts since it is important.

If you can, remove the extraneous LinearLayouts as I mentioned in my comment above. This can make your life easier. Otherwise debugging this layout may mean "an all-nighter".

I have solved my problem ! In fact, the LinearLayout was behind the navigationBar. To fix it, just add this line to the Activity (after setContentView();) :

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

Thanks for answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM