我有一个ActionBarActivity片段.我正在使用FragmentPagerAdapter它为我的应用程序提供片段.我的问题如何在Fragment中访问父Activity视图?
我刚刚使用CoordinatorLayout尝试了新的支持设计库,但是我在锚定子视图时遇到了问题.我的布局目前看起来像这样:
<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/coordinator_layout"
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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor="@id/toolbar"
app:layout_anchorGravity="bottom"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_fab_add"
android:onClick="onAddPlayerClick"
android:layout_gravity="bottom|end"
app:elevation="4dp"
app:borderWidth="0dp"/>
Run Code Online (Sandbox Code Playgroud)
加载RecyclerView列表时,操作栏会重叠第一个项目.我假设app:layout_anchor无法正常工作.我已经尝试将其锚定到appbar但没有成功.
有谁知道我在做错了什么?
android android-recyclerview android-design-library coordinator-layout
我有一个抽屉的主要活动,其中有一个container layout我将每个片段替换为FragmentManager.
我想向我的一个子片段添加一个 FAB,该片段在滚动时隐藏/显示,但我不确定我做错了什么并得到:
布局:
<?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.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?actionBarSize"
android:theme="@style/Toolbar"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
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.FloatingActionButton
style="@style/Widget.Design.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_medium"
android:elevation="@dimen/elevation_little"
app:fabSize="normal"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:srcCompat="@drawable/ic_add_white_18dp" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-fragments material-design floating-action-button android-coordinatorlayout