【发布时间】:2015-11-24 23:32:25
【问题描述】:
我在 CoordinatorLayout 中使用 FloatingActionButton 处理奇怪的边距行为。 FAB 添加额外的边距,在某些操作后消失。
我按照Cheesesquare 示例创建详细视图。我有完全相同的 xml 结构。唯一的区别是我将此视图用于片段而不是原始活动。
这在大多数情况下都会发生,但有时不会。片段对象只发生一次,一旦它自行修复它就会很好地工作。在我的第二部手机上,它不会发生。删除FAB后就OK了。当我在日历中更改某事时,它也会导致边距自行修复。
在启用布局线的情况下附加 gif,以便您可以看到边距。
供参考:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content2"
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"
android:background="@color/white"
android:fitsSystemWindows="true"
tools:context="com.habitsteacher.android.view.fragment.show.ShowHabitFragment">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="72dp"
app:expandedTitleMarginEnd="24dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<TextView
android:id="@+id/intentionText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="16dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="24dp"
android:layout_marginStart="48dp"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:maxLines="2"
android:textColor="@color/icons"
android:textSize="@dimen/abc_text_size_subhead_material"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.25"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_show_habit"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</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">
<LinearLayout
android:id="@+id/habit_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:orientation="vertical"
android:paddingTop="32dp">
<android.support.v7.widget.CardView
android:id="@+id/calendarWrapper"
android:layout_width="match_parent"
android:layout_height="343dp"
android:layout_margin="@dimen/card_margin">
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_button_edit_habit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
android:src="@drawable/ic_mode_edit_white_24dp"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
有没有想过可能是什么原因,或者如何深入调查?
【问题讨论】:
标签: android android-layout android-design-library android-coordinatorlayout floating-action-button