1

I have a tab with listview but I can't see the last element unless I scroll the Actionbar(which I think should not be normal)

Here is my xml:

<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.dikelito.tabs.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <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:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

Picture 1 Picture 2

How can I fix this?

2 Answers2

1

This solved the problem for me:

ViewCompat.setNestedScrollingEnabled(yourListView, true);
Bugs
  • 4,491
  • 9
  • 32
  • 41
Harsh Masand
  • 121
  • 1
  • 4
0

This is the correct behavior. Your list is using the available space but when you swipe up the toolbar collapses and gives your list more room to show the last entry.

The top item in your list is being overlapped by the toolbar. That may be caused by the android:paddingTop="@dimen/appbar_padding_top" attribute in the <android.support.design.widget.AppBarLayout element of your layout.

edit - Adding additional info from comments

CoordinatorLayout works with views that support NestedScrollView. For ListView, be sure to add ViewCompat.setNestedScrollingEnabled(yourListView, true); in onCreateView()

Don Shrout
  • 865
  • 10
  • 17
  • The problem is that the toolbar is not collapsing. – Deyan Dimitrov Feb 17 '17 at 18:17
  • Your second image shows the toolbar collapsed. Are you saying that is not happening when you swipe up or are you trying to hide the tabs as well? – Don Shrout Feb 17 '17 at 18:21
  • It is collapsing only when I scroll the toolbar. It is not collapsing when I scroll the listview. I've read http://stackoverflow.com/a/17767691/4778015 but the toolbar is not collapsing and I don't know what I'm missing – Deyan Dimitrov Feb 17 '17 at 18:36
  • CoordinatorLayout works with views that support NestedScrollView. Try adding this `ViewCompat.setNestedScrollingEnabled(yourListView, true);` in `onCreateView` – Don Shrout Feb 17 '17 at 18:57
  • OK, I thought it was working but it is not on android 4.4 and below. – Deyan Dimitrov Feb 18 '17 at 12:13
  • Sorry to leave you hanging for so long. It was a busy weekend for me and I didn't get on my computer at all. Try using a RecyclerView instead of a ListView. – Don Shrout Feb 20 '17 at 13:25
  • @DeyanDimitrov, did you get a chance to try a RecyclerView instead of a ListView? If so, did it solve your issue with Android 4.4? – Don Shrout Feb 23 '17 at 12:18