Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the action bar causes bottom aligned item in RelativeLayout to jump

i have RelativeLayout with a view that is aligned to the parent bottom. when i call actionBar.hide() the view slides up as the action bar slides up, then once the action bar has fully disappeared, the view jumps back to the bottom.

how do i prevent this from happening? i want the view to stay attached to the bottom as the action bar slides up.

can't embed images so here's a link

the tabs are what are bottom aligned. (the grey stuff you see above is a different fragment being loaded so ignore that)

Code:

public class MainFragment extends Fragment {
    public View onCreateView(...) {
        return inflater.inflate(R.layout.fragment_main);
    }
    public void onResume() {
        super.onResume();
        getActivity().getActionBar().hide();
    }
    public void onPause() {
        super.onPause();
        getActivity().getActionBar().show();
    }
}

R.layout.fragment_main:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="test" />
</RelativeLayout>
like image 770
fsociety Avatar asked Mar 09 '17 02:03

fsociety


1 Answers

Set action bar overlay mode in your AppTheme style:

<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->  
<item name="windowActionBarOverlay">true</item>

(more info)

and, if you need, set padding or margin in your layout file like this: ?android:attr/actionBarSize

like image 57
igor_rb Avatar answered Nov 09 '22 07:11

igor_rb