问题
I have a layout in which a button is aligned at the bottom of the RelativeLayout as in below code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="250dp"
android:background="@color/background_material_light"
android:layout_height="match_parent">
<View
android:layout_alignParentLeft="true"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/strokeColor"/>
<RelativeLayout
android:id="@+id/rlHeaderFilter"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material">
<View
android:id="@+id/separator"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/strokeColor"/>
<TextView
android:background="@color/actionbar_background"
android:id="@+id/tvFilterText"
style="@style/textStyleHeading2"
android:layout_toRightOf="@+id/separator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="@color/white"
android:text="Filter Search" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:src="@drawable/refresh"
android:id="@+id/resetLeadsFilter"
android:contentDescription="@string/emptyString"
android:layout_centerVertical="true"
android:padding="6dp"/>
</RelativeLayout>
<TextView
android:layout_below="@+id/rlHeaderFilter"
android:layout_marginTop="10dp"
android:id="@+id/tvBudgetFromFilter"
style="@style/textSpinnerStyleHeading"
android:layout_margin="8dp"
android:hint="Budget From"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/tvBudgetFromFilter"
android:layout_marginTop="10dp"
android:id="@+id/tvBudgetToFilter"
style="@style/textSpinnerStyleHeading"
android:layout_margin="8dp"
android:hint="Budget To"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_below="@+id/tvBudgetToFilter"
android:id="@+id/sourceLayout"
layout="@layout/source_layout" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/statusLayout"
android:layout_margin="8dp"
android:layout_below="@+id/sourceLayout"
layout="@layout/status_layout" />
<Button
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:textColor="@color/white"
android:background="@color/actionbar_background"
android:text="SEARCH"
android:id="@+id/bFilterLeads"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
I can see the button at the bottom of the layout as shown in the screenshot .It displays like this in pre Lollipop devices(below < 5.0 devices) :
But in Lollipop the button at the bottom does not appear as shown in following screenshot :
I am not able to get the reason for that Please help me out . Thanks in advance .
回答1:
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);
回答2:
I'm not sure why the layout behaves differently between Lollipop/pre-Lollipop (unless there's some other piece that's not shown). I will point out though that I don't think layoutGravity
is valid for views within a RelativeLayout
-- that's something you'd use with a LinearLayout
. I'd first remove that property and see how it behaves on pre-Lollipop, and then see about correcting the layout once that's done. It could be that layoutGravity
is causing some sort of incorrect behavior pre-Lollipop.
来源:https://stackoverflow.com/questions/28678555/layout-alignment-issue-in-android-5-0