繁体   English   中英

CoordinatorLayout layout_anchor不适用于Floating action botton

[英]CoordinatorLayout layout_anchor does not work with Floating action botton

我在GitHub上使用此FAB时遇到问题,无法正确使用我在XML文件viewA: 布局中命名的自定义工具栏进行锚定,出现了我尝试使用coordinator_layout尝试解决的问题,但似乎无法使其正常工作。

我希望将其锚定到右下角的viewA

我目前的布局

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_subject"
    tools:context="com.example.coquenim.gradebook.Activities.SubjectActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:id="@+id/viewA"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:layout_height="60dp"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
           >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Your grade"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="70dp"
                android:paddingEnd="70dp"
                android:paddingStart="@dimen/activity_horizontal_margin"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Goal"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:divider="@drawable/divider"
            android:dividerPadding="8dp"
            android:orientation="horizontal"
            android:showDividers="middle"
            >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="50sp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="18.75"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:id="@+id/subjectAveragee"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="50sp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="20.00"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:id="@+id/subject_target_grade"
                />
        </LinearLayout>

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/currentSubjectName"
        android:padding="8dp"
        android:textIsSelectable="false"
        android:textSize="24sp"
        android:textColor="@color/textColorBlack"
        android:layout_below="@+id/viewA"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/expandableListView"
        android:childDivider="#00000000"
        android:layout_below="@+id/currentSubjectName"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu_down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|right|end"
        android:elevation="5dp"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true"
        fab:menu_openDirection="down">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_add_box_white_24dp"
            fab:fab_showAnimation="@anim/show_from_bottom"
            fab:fab_hideAnimation="@anim/hide_to_bottom"/>

    </com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>

从库的github看一下这种布局 他们通过具有固定高度的标头并使用填充/边距使FAB沿着标头TextView的底部对齐来实现看起来像锚点的效果,使其看起来像在实现CoordinatorLayoutlayout_anchor

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM