1
votes

CoordinatorLayout rend les vues non positionnées

Désolé pour mon mauvais anglais. J'essayais de faire défiler la barre d'outils avec recyclerview en utilisant Coordinatorlayout. Le défilement fonctionne bien mais les vues passent sous la barre d'outils, comme la mise en page d'actualisation par balayage Afficher dans capture d'écran . Activity_main.xml Im implémentation d'un fragment dans FrameLayout mobile_container

<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>

La mise en page du fragment

<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 >


5 commentaires

Ajoutez toutes vos vues et ViewsGroup à l'intérieur d'un LinearLayout et rendez ses oriations verticales comme mentionné dans la réponse de @ Kilran.Merci ....



bro c'est déjà là


rendre la largeur "match_parent"


où son besoin match_parent


3 Réponses :


1
votes

Votre LinearLayout contenant la vue du recycleur sous la forme android: layout_height = "match_parent" donc il prendra toute la hauteur de l'écran car le parent est la disposition racine.

Vous devez faire ceci LinearLayout prend toute la hauteur moins la hauteur de la barre d'en-tête

Vous pouvez le faire facilement:

<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>

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

En fait, vous n'avez même pas besoin de cette mise en page linéaire essayez ceci (comme suggéré par Rahul Kushwaha, enveloppez le tout dans LinearLayout mais vous n'avez pas besoin du LinearLayout interne):

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


1 commentaires

les vues à l'intérieur du layout sont maintenant totalement invisibles



0
votes

Définissez votre propriété LinearLayout android:layout_marginTop="?attr/actionBarSize"


1 commentaires

J'ai déjà essayé cela, mais lorsque la barre d'outils défile, il y a un espace blanc entre la barre d'outils et d'autres mises en page



3
votes

Faites comme ça. J'espère que ça marche.

<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 >


2 commentaires

Cela a fonctionné mais la barre d'outils ne défile pas avec recyclerview


@Brown Vous savez peut-être que "la barre d'outils devrait toujours être corrigée dans une activité".