0

I have list of item which I want to display in recyclerview and in the main layout I added CollapsingToolbarLayout .Before applying CollapsingToolbarLayout recyclerview worked fine but after adding it to layout it is not visible.

Here is the layout file in which i added collapsingtoolbar layout activity_main.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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:background="@color/material_deep_teal_500"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/MyToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="parallax" />

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

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

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/rv"
        />


</android.support.v4.widget.NestedScrollView>

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

I followed this tutorial to work with collapsingtoolbarlayout
here is the main activity

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.MyToolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout) findViewById(R.id.collapse_toolbar);
        collapsingToolbar.setTitle("My Toolbar Tittle");
        ArrayList<AppModel> arrayList = getDataFromDataBase();
        try {
            RecyclerView recyclerView = (RecyclerView)findViewById(R.id.rv);
            recyclerView.setHasFixedSize(false);

            recyclerView.setItemAnimator(new DefaultItemAnimator());
            recyclerView.setLayoutManager(new LinearLayoutManager(this));
            recyclerView.setAdapter(new AppsListAdapter(this,arrayList));
        }catch (Exception e){
            Toast.makeText(this,e.getMessage(),Toast.LENGTH_LONG).show();
        }

here are my gradle dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
}

enter image description here

I have tried with solutions for the similar question in stackoverflow but it didn't work.Please help me .did i do any thing wrong ?

Punit Sharma
  • 2,951
  • 1
  • 17
  • 32
Tirupati Rao
  • 577
  • 4
  • 22

1 Answers1

1

no need to use nestedscrollview, you only need the recyclerview

    <?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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:background="@color/material_deep_teal_500"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/MyToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="parallax" />

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

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



    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/rv"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

    </android.support.design.widget.CoordinatorLayout>
aiwiguna
  • 2,417
  • 2
  • 12
  • 24
  • Hi.I tired with your solution.It is working but appbar is appearing below the recyclerview . – Tirupati Rao Jan 30 '16 at 16:19
  • that weird,i have more complicated layout in my project and its working fine. here example from my project http://pastebin.com/AqgHSsBT , here more complicated layout http://pastebin.com/6z7BPQnw – aiwiguna Jan 30 '16 at 16:28
  • btw, you better use same version of library com.android.support:****, dont have different version 22.2.0 and 23.0.1 like that, because it may cause some error – aiwiguna Jan 30 '16 at 16:34
  • Thank you for the suggestion . – Tirupati Rao Jan 30 '16 at 16:36
  • Its my bad i didnt add app:layout_behavior="@string/appbar_scrolling_view_behavior" to the recyclerview .Thanks works great (Y) – Tirupati Rao Jan 30 '16 at 16:36