java - Collapsing Toolbar and Fragment -


i have app laid out this, mainactivity hosts 2 tabs accompanied fragments, first fragment has recycler view works, i'm trying add parallax effect person scrolls or down, wasn't sure if should add fragment's xml or mainactivity's xml, added mainactivity's xml , included fragment recyclerview, needless parallax didn't work , app doesn't open , nullpointerexception didn't touch code.please point me in correct direction.

xml below

frag1.xml

<?xml version="1.0" encoding="utf-8"?>  <relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent">  <android.support.v7.widget.recyclerview         android:id="@+id/my_recycler_view"         android:scrollbars="vertical"         android:layout_width="match_parent"         android:layout_height="match_parent"/>   </relativelayout> 

mainactivity.xml

<android.support.design.widget.coordinatorlayout     android:id="@+id/main_layout"     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"     tools:context=".mainactivity">      <android.support.design.widget.appbarlayout         android:layout_height="100dp"         android:layout_width="match_parent"         android:fitssystemwindows="true"         >          <android.support.design.widget.collapsingtoolbarlayout             app:layout_scrollflags="scroll|exituntilcollapsed"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:fitssystemwindows="true">              <imageview                 android:layout_height="match_parent"                 android:layout_width="match_parent"                 app:layout_collapsemode="parallax"                 />                <android.support.v7.widget.toolbar                 android:id="@+id/toolbar"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_alignparenttop="true"                 android:background="@color/colorprimary"                 android:elevation="6dp"                 android:minheight="?attr/actionbarsize"                 android:theme="@style/themeoverlay.appcompat.dark.actionbar"                 app:popuptheme="@style/themeoverlay.appcompat.light"                 app:layout_collapsemode="pin"/>              </android.support.design.widget.collapsingtoolbarlayout>      </android.support.design.widget.appbarlayout>       <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical"         app:layout_behavior="@string/appbar_scrolling_view_behavior">           <android.support.design.widget.tablayout             android:id="@+id/tab_layout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_below="@+id/toolbar"             android:background="?attr/colorprimary"             android:elevation="6dp"             android:minheight="?attr/actionbarsize"             android:theme="@style/themeoverlay.appcompat.dark.actionbar"             app:layout_scrollflags="enteralways"             />          <android.support.v4.view.viewpager             android:id="@+id/pager"             android:layout_width="match_parent"             android:layout_height="fill_parent"             android:layout_below="@id/tab_layout"             app:layout_behavior="@string/appbar_scrolling_view_behavior"/>             </linearlayout>   </android.support.design.widget.coordinatorlayout> 

crash log excerpt

07-08 19:43:54.671    2264-2264/com.example.dimple.test e/androidruntime﹕ fatal exception: main process: com.example.dimple.test, pid: 2264 java.lang.nullpointerexception: attempt invoke virtual method 'void android.support.v7.widget.recyclerview$layoutmanager.onmeasure(android.support.v7.widget.recyclerview$recycler, android.support.v7.widget.recyclerview$state, int, int)' on null object reference         @ android.support.v7.widget.recyclerview.onmeasure(recyclerview.java:1764)         @ android.view.view.measure(view.java:17430)         @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:727)         @ android.widget.relativelayout.onmeasure(relativelayout.java:463)         @ android.view.view.measure(view.java:17430) 

full log can found here http://pastebin.com/4cpgtx2z

you want set this:

<android.support.design.widget.coordinatorlayout>      <android.support.design.widget.appbarlayout>      <android.support.design.widget.collapsingtoolbarlayout         app:layout_scrollflags="scroll|exituntilcollapsed">              <imageview                 app:layout_collapsemode="parallax"/>              <android.support.v7.widget.toolbar />          </android.support.design.widget.collapsingtoolbarlayout>      </android.support.design.widget.appbarlayout>      <linearlayout         app:layout_behavior="@string/appbar_scrolling_view_behavior" >          <android.support.design.widget.tablayout />         <android.support.v4.view.viewpager />      </linearlayout>  </android.support.design.widget.coordinatorlayout> 

this give parallax effect fragments inside viewpager.

make sure add the:

android:fitssystemwindows="true"

attribute both appbarlayout , collapsingtoolbarlayout, , attribute toolbar:

app:layout_collapsemode="pin"

if want add fragment can add framelayout so:

<android.support.design.widget.coordinatorlayout>      <android.support.design.widget.appbarlayout>         <!-- collapsingtoolbarlayout -->     </android.support.design.widget.appbarlayout>      <linearlayout >         <android.support.design.widget.tablayout />         <android.support.v4.view.viewpager />     </linearlayout>      <framelayout />  </android.support.design.widget.coordinatorlayout> 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -