我正在使用Android支持FloatingActionButton
(FAB)和CoordinatorLayout
,我希望將FAB定位到CardView
。Anchor FloatingActionButton
這是我的代碼:
<android.support.design.widget.CoordinatorLayout
... />
<LinearLayout
...>
<android.support.v7.widget.CardView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
...
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:src="@android:drawable/ic_menu_send"
app:layout_anchor="@id/container"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
這工作,但有時FAB出現在頁面的左上角上方側,不固定。
在這種情況下,當我按FAB鍵時,它會回來錨定。 CardView
不是CoordinatorLayout
的直接子項,但我使用的[支持庫24.2.1]允許這樣做。
可能是什麼問題?
是否包含其他視圖的線性佈局? –
是的,LinearLayout包含其他視圖 – Stefano