相关疑难解决方法(0)

带有 FAB 的片段布局与 CoordinatorLayout 冲突

我使用MaterialDrawer并根据所选项目MainDrawerActivity替换容器 内的每个片段FrameLayout,但我想添加一个与之交互的 FAB(仅用于此片段),CoordinatorLayout以便它可以处理很酷的动画。

主抽屉布局:

<?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.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我如何替换每个片段:

try {
  supportFragmentManager.beginTransaction().replace(R.id.container, FeedFragment()).commit()
} catch (e: IllegalStateException) {
  Timber.i(e, "Fragment is still there.")
}
Run Code Online (Sandbox Code Playgroud)

片段布局:

<FrameLayout 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.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:listitem="@layout/feed_item" />

  <android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="@dimen/spacing_medium" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments material-design floating-action-button android-coordinatorlayout

5
推荐指数
1
解决办法
1389
查看次数

CoordinatorLayout末尾的浮动动作按钮

我正在尝试在CoordinatorLayout中移动按钮,但效果不佳。

注意:这不是一个晶圆厂按钮!在背景中还有2个以上不可见。还有一个不可见的cardview,在这种情况下,我的fab按钮不在右下角。

尝试过的事情:我尝试遵循CoordinatorLayout,FAB和容器布局冲突

在此处输入图片说明

布局

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/cardview_default_margin">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="@dimen/padding_detail_card">

                    <!-- Nominativo -->
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/tv_nominativo"
                        style="@style/AppTheme.NoActionBar.Text.Primary"/>

                    <!-- Identificativo -->
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/tv_identificativo"
                        style="@style/AppTheme.NoActionBar.Text.Primary"/>

                    <!-- Data -->
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/tv_data"
                        style="@style/AppTheme.NoActionBar.Text.Primary"/>

                    <!-- Indirizzo -->
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/tv_indirizzo"
                        style="@style/AppTheme.NoActionBar.Text.Primary" />

                    <!-- Telefono -->
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/tv_telefono"
                        style="@style/AppTheme.NoActionBar.Text.Primary" />
                </LinearLayout>
            </android.support.v7.widget.CardView>
            <android.support.v7.widget.CardView
                android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android floating-action-button android-coordinatorlayout

0
推荐指数
1
解决办法
1129
查看次数