我遇到问题this FAB from GitHub要正确锚定我在xml文件中命名的自定义工具栏a:layout with problem 我尝试使用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>
答案 0 :(得分:0)
从图书馆的github看一下this layout。他们通过使用固定高度标题并使用填充/边距来对齐标题TextView
底部的FAB来实现看起来像锚点,看起来它实现了CoordinatorLayout
' s layout_anchor
。