Error with Coordinatorlayout

Asked

Viewed 773 times

0

XML:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="6dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Opção de Pesq.: "
                    android:textColor="@color/black"
                    android:textSize="@dimen/font_size_normal" />

                <Spinner
                    android:id="@+id/comboOpcaoPesqCliente"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawSelectorOnTop="true"
                    android:textSize="@dimen/font_size_normal" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="6dp">

                <EditText
                    android:id="@+id/edPesquisaCliente"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="Digite para pesquisar"
                    android:imeOptions="actionDone"
                    android:singleLine="true"
                    android:textSize="@dimen/font_size_editText" />

                <Button
                    android:id="@+id/btLimpar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Limpar"
                    android:textColor="@color/black"
                    android:textSize="@dimen/font_size_normal" />
            </LinearLayout>
        </LinearLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewListaClientes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/white"
                android:cacheColorHint="@android:color/transparent"
                android:clipToPadding="false"
                android:divider="@null"
                android:dividerHeight="0dp"
                android:listSelector="@android:color/transparent"
                android:scrollbarStyle="outsideOverlay"
                android:scrollbars="vertical" />

            <ProgressBar
                android:id="@+id/progressBar"
                style="@android:style/Widget.ProgressBar.Large"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center|center_vertical"
                android:layout_marginRight="6dp"
                android:visibility="invisible" />

        </FrameLayout>
    </LinearLayout>

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

I added this to Activity in Manifest:

android:windowSoftInputMode="adjustPan"

What’s going wrong is this::

When I rotate the list down and the Toolbar hides and I click on an Edittext and the keyboard opens, then when I close the keyboard and scroll the list up, the Toolbar simply disappears, but this only happens when the keyboard opens when the Toolbar is hidden:

Photo: Before:

inserir a descrição da imagem aqui

Afterward:

inserir a descrição da imagem aqui

  • If you scroll the screen up, will Toolbar appear or will it remain hidden forever? I don’t understand why LinearLayout is with the behavior, only the RecyclerView need to have it.

  • This way I made the Toolbar works properly, if I scroll the list down the Toolbar appears, if I scroll the list up the Toolbar disappears. Only when the Toolbar is hidden and I open the keyboard and type something and close the keyboard, when I scroll the list down, the Toolbar appears, but it is all gray, like the photo I posted above. If I take the behavior from Linearlayout and put it into Recyclerview, Linearlayout is over the Toolbar. Recyclerview behavior image: http://i.stack.Imgur.com/Uldrp.png

  • Rodrigo, I think it’s right to keep the RecyclerView. The problem in this case is the use of android:fitsSystemWindows. If you do not use the NavigationView, is the case of taking these attributes from all views of this layout, which will solve this problem.

  • I took android:fitsSystemWindows and changed the behavior from Linearlayout to Recyclerview and Linearlayout continued on the Toolbar

  • Could it be the version I’m compiling? I’m using these: Compile 'com.android.support:appcompat-v7:22.2.0' / Compile 'com.android.support:design:22.2.0'

  • I doubt it very much, but it is always good to use the latest versions (23.1.1 today). I will try to set an example here and reproduce the problem to be able to investigate better.

  • Man, if you could do that, I’d really appreciate it. I have been with this problem for a long time, but some more important things came up to do in the app and I put this aside, now that I have a little time left that I am resuming this. Vlw. I will edit the main post with full XML

  • In a way I discovered the problem. The LinearLayout is below the AppBarLayout because I asked to take the behavior (the behavior is who makes it stand below). Returning with the behavior in the LinearLayout (without Recyclerview), keeping without the attribute fitsSystemWindows solves the problem?

  • I did it like you said, then returned as it was before, Linearlayout does not stay on the Toolbar and the Toolbar works perfectly. But there is that problem of the keyboard being opened when the Toolbar is

  • I recorded a video of what is happening: http://sendvid.com/gffll5yj . Note that the Toolbar only turns gray when the keyboard is opened when it is hidden, and then when I open the keyboard again it appears in normal color.

  • I find it very strange, I do not know if it is a bug of the appcompat implementation. But here I did the same test (with a slightly simpler layout) and no problem. This layout is also very complex, I do not know if you simplify it to try to find the cause of the problem helps. Looking closer, I don’t think Toolbar is gray, he didn’t come back I guess.

  • What do you suggest to me to simplify the layout? I haven’t tried yet with version 23.1.1 , because I haven’t installed it here, so I’ll try to install it...

  • The first thing that came to me is that it has a LinearLayout redundant vertical there, nested. It has some strange dimensions, like a guy layout_height=wrap_content with a son being layout_height=match_parent, in which case it would be nice to adjust too (it’s not good to have a father wrap_content and son match_parent).

  • I changed to version 23.1.1 and it worked, it was a bug of the previous version. Vlw..

  • Pasta, could put a response commenting on this solution. Can help other people.

Show 10 more comments

1 answer

1


Problem solved.

Before I was using these versions:

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'

I started wearing these:

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

Apparently it is a bug of version 22.2.0

  • Rodrigo, don’t forget to mark it as correct :D

  • Yes, I was marked as correct and says I can only mark my own response tomorrow haha

  • Blz, no cricket :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.