Reputation: 1590
I have a FrameLayout in my app that is being replaced by a Fragment that contains a RecyclerView, but when it does that, the RecyclerView doesn't fill up the whole FrameLayout, there's a border around it.
Parent Layout, this is what is called from MainActivity, it contains the FrameLayout that is going to be replaced:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.jggdevelopment.wannacook.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/relative_layout_for_fragment"
tools:showIn="@layout/navigation_toolbar"
tools:context="com.jggdevelopment.wannacook.MainActivity"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Fragment it's being replaced with, a RecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/fridge_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/fab_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/floating_button"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="left"
fab:fab_icon="@drawable/ic_plus_white_24dp"
fab:fab_addButtonColorNormal="@color/colorAccent"
fab:fab_addButtonColorPressed="@color/colorAccentPressed">
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addNewItem"
fab:fab_colorNormal="@color/white"
fab:fab_colorPressed="@color/whitePressed"
fab:fab_title="Add new item"
fab:fab_icon="@drawable/ic_restaurant_black_24dp"
/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>
Code in MainActivity used to replace Fragment:
else if (id == R.id.nav_fridge) {
FridgeFragment fridgeFragment = new FridgeFragment();
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(
R.id.relative_layout_for_fragment,
fridgeFragment,
fridgeFragment.getTag()
).commit();
}
Upvotes: 0
Views: 1411
Reputation: 9225
Make this changes in your Frame Layout
remove:
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
Or use this Frame Layout in your layout (i have made the changes )
<FrameLayout
android:id="@+id/relative_layout_for_fragment"
tools:showIn="@layout/navigation_toolbar"
tools:context="com.jggdevelopment.wannacook.MainActivity"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
</FrameLayout>
Upvotes: 1
Reputation: 151
Please remove padding on FrameLayout.
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
Upvotes: 1