Android: height not respected through FragmentTransactions

So, I have a layout that looks something like this:

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_height="wrap_content" android:elevation="4dp" android:background="?attr/colorPrimary" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize"/> <FrameLayout android:id="@+id/content" android:layout_below="@+id/toolbar" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> 

This forms my main layout file for my activity, and then I replace FrameLayout for various fragments. One such fragment has the following form:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <SlidingTabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:elevation="4dp" android:layout_height="wrap_content"/> <android.support.v4.view.ViewPager android:id="@+id/profileViewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/sliding_tabs" android:background="@android:color/white"/> <FloatingActionButton android:id="@+id/floatingButton" android:layout_width="72dp" android:layout_height="72dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginRight="16dp" android:layout_marginBottom="16dp"/> </RelativeLayout> 

I would expect that since I set the elevation of both the toolbar and SlidingTabLayout to 4dp, the toolbar will not cast a shadow over the tabs, however it does the following:

Screen shot

Ideally, I would not want to set the height of the toolbar in the code - does anyone know if there is a way to prevent the toolbar from being used in the shadow? I would suggest that since both views are at 4dp, although they are not in the same layout, no shadow will be selected.

Thanks for the help.

+5
source share
1 answer

Shadows respect the exaltation of brothers and sisters, but not cousins. The action bar and SlidingTabLayout are not siblings, so the action bar casts a shadow over SlidingTabLayout.

You need to customize the action bar to remove the height if you don't need a shadow.

+5
source

Source: https://habr.com/ru/post/1206017/


All Articles