Da Bilder immer besser als Worte sind, präsentiere ich Ihnen my current layout.AppBarLayout mit recyclerView im verschachtelten Fragment
Die Symbolleiste/Registerkarten befinden sich in einer activity.xml mit einem viewPager, und die recycleView befindet sich in einem Fragment innerhalb des viewPagers. Sie können also nach rechts/links wischen, um andere Inhalte zu sehen.
Mein Problem ist, dass ich möchte, dass das AppBarLayout in seinem Scroll-Verhalten an die RecyclerView im ersten Fragment gebunden ist, aber nicht zu den anderen Fragmenten.
Im Code unten, habe ich diese Bindung, aber es funktioniert nicht, weil die RecyclerView das AppBarLayout im äußeren Layout nicht erkennt. Haben Sie einen Workaround dafür?
-Code für die Aktivität:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
/* pretty stuff */
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/* pretty stuff */ />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/main_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.SupportFloatingActionsMenu
...>
/* Code for a fancy fab w/ menu */
</android.support.design.widget.SupportFloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>
Für das Fragment, das den recyclerView:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.insa.burnd.view.MainActivity.NewsfeedFragment"
android:id="@+id/fragment_newsfeed">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
Vielen Dank :)!
Sie die gleiche Frage/Code hier gefragt: http://stackoverflow.com/questions/ 31144526/tablayout-inside-toolbar –
Nein. Es ist nicht dasselbe. Die Frage ist sehr unterschiedlich, der Code ist ziemlich der gleiche (und das gif ist das gleiche). – Mehdi