【问题标题】:How to position layouts vertically in coordinatorLayout如何在 coordinatorLayout 中垂直放置布局
【发布时间】:2016-10-11 10:05:36
【问题描述】:

我想在我的片段中实现折叠布局。但是我的 collapsingLayout、framelayout(容器)和 tablayout 的位置就像它们放在框架布局中一样。
我想在顶部制作 Collapsinglayout,在其下方制作 tablayout,在 tablayout 下方制作框架布局容器,保留折叠动画。 (frame layout container承载recyclerview组成的各种fragment【由于各种自定义手势,不考虑viewpager】)

fragment_layout.xml

<android.support.design.widget.CoordinatorLayout 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/appBgColor"
    android:clickable="true"
    tools:context="com.lunchpoint.fragments.RestaurantFragment"

    >
  <android.support.design.widget.AppBarLayout
      android:id="@+id/id_appbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@android:color/transparent"
      android:fitsSystemWindows="true"
      >

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        >

      <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="310dip"
          >
       <!--Header layout-->
      </RelativeLayout>

    </android.support.design.widget.CollapsingToolbarLayout>

  </android.support.design.widget.AppBarLayout>
  <android.support.design.widget.TabLayout
      android:id="@+id/tabs"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"

      android:layout_marginEnd="16dip"
      android:layout_marginLeft="16dip"
      android:layout_marginRight="16dip"
      android:layout_marginStart="16dip"
      app:tabGravity="fill"
      app:tabMinWidth="0dip"
      app:tabMode="scrollable"
      app:tabPaddingEnd="1dp"
      app:tabPaddingStart="1dp"
      />

  <FrameLayout

      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      />

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

    标签: android android-fragments android-coordinatorlayout


    【解决方案1】:

    您可以轻松地结合使用锚属性和 layout_gravity 来实现此目的。参见,例如:http://ponshere.in/blog/android-coordinator-layout-gravity-and-alignment/

    【讨论】:

      【解决方案2】:

      CoordinatorLayout 是一个强大的 FrameLayout:所有的孩子都可以通过一个行为或一个锚来定义他们的位置。查看更多文档,例如 this

      【讨论】:

      • 我觉得链接没有回答问题。
      • 我们知道所有这些限制,因此这没有提供解决方案。
      猜你喜欢
      • 1970-01-01
      • 2019-03-03
      • 2011-11-06
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      • 2012-02-15
      • 2014-10-07
      • 2012-10-25
      相关资源
      最近更新 更多