Brown
Brown

Reputation: 23

CoordinatorLayout Makes views Unpositioned

Sorry for my bad English. I was trying to make scrolling Toolbar with recyclerview using Coordinatorlayout. The scrolling works fine but the views gets under the toolbar,like swipe refresh layout Show in screenshot. Activity_main.xml Im implementing a fragment in FrameLayout mobile_container

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.naveed.youtubepro.activity.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:title="@string/app_name">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

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

        <FrameLayout
            android:id="@+id/mobile_container"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>
        <me.majiajie.pagerbottomtabstrip.PageNavigationView
            android:id="@+id/navigation"
            android:elevation="8dp"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:layout_alignParentBottom="true"
            android:background="#FFF"
            app:menu="@menu/bottom_navigation_items"/>

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout >

The fragment layout

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="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:id="@+id/mainandroid.support.v4.widget.SwipeRefreshLayout">
    <com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recyclerViee"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>

Upvotes: 1

Views: 72

Answers (3)

Alpesh Vaghasiya
Alpesh Vaghasiya

Reputation: 186

Set your LinearLayout Property android:layout_marginTop="?attr/actionBarSize"

Upvotes: 0

Kilarn123
Kilarn123

Reputation: 733

Your LinearLayout holding the recycler view as android:layout_height="match_parent" so it will take all the height of the screen bacause the parent is the root layout.

You have to make this LinearLayout take all the height minus the header bar height

You can do this easily :

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1">
    <!-- frame and bottom navigation -->
</LinearLayout>

============== UPDATE ==============

Actually you don't even need this LinearLayout try this (as suggested by Rahul Kushwaha, wrap the whole thing in LinearLayout but you don't need the inner LinearLayout):

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/txt_forget_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:title="@string/app_name">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/mobile_container"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

    </FrameLayout>
    <me.majiajie.pagerbottomtabstrip.PageNavigationView
        android:id="@+id/navigation"
        android:elevation="8dp"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="#FFF"
        app:menu="@menu/bottom_navigation_items"/>

</LinearLayout>

Upvotes: 1

Rahul Kushwaha
Rahul Kushwaha

Reputation: 6722

Do Like This .Hope this works.

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/txt_forget_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:title="@string/app_name">
            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.AppBarLayout>

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

            <FrameLayout
                android:id="@+id/mobile_container"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="0dp">

            </FrameLayout>
            <me.majiajie.pagerbottomtabstrip.PageNavigationView
                android:id="@+id/navigation"
                android:elevation="8dp"
                android:layout_width="match_parent"
                android:layout_height="56dp"
                android:background="#FFF"
                app:menu="@menu/bottom_navigation_items"/>

        </LinearLayout>

    </LinearLayout>



</android.support.design.widget.CoordinatorLayout >

Upvotes: 3

Related Questions