[英]Floating Action Button Not In Bottom Right
由於某種原因,我的 FAB 不會像往常一樣進入屏幕的右下角。 我在一個片段中,該片段是一個協調器布局(我不知道這是否是一個好習慣)。
這是布局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"
tools:context="com.gigstudios.polls.fragment.MyPollsFragment">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_white_36dp"
app:fabSize="normal"
app:layout_anchor="@id/linear_layout"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
出於某種原因,FAB 最終位於右上角而不是右下角。 有誰知道我做錯了什么?
順便說一句,xml 預覽總是在右下角顯示 fab 按鈕,但是當我在手機上運行它時,它在右上角。
編輯:這是我的 main_activity xml,用於顯示我放置片段的位置(“容器”FrameLayout)。
<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:background="@color/colorGrey">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrey"
android:layout_marginTop="?attr/actionBarSize">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
這個問題是由於android.support.v4.widget.NestedScrollView
添加了一個字段android:fillViewport="true". Issue was coming as your
android:fillViewport="true". Issue was coming as your
NestedScrollView 未擴展以匹配父級或占用可用空間,因此出現問題。 用我的代碼測試工作正常
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:fillViewport="true"
android:layout_marginTop="?attr/actionBarSize">
</android.support.v4.widget.NestedScrollView>
刪除線條
app:layout_anchor="@id/linear_layout"
app:layout_anchorGravity="bottom|right|end"
在您的FloatingActionButton
。 他們沒有做任何事情(因為您錨定到填充整個CoordinatorLayout
的視圖)。 這將導致您的layout_gravity
受到尊重,並且您的FloatingActionButton
將被放置在CoordinatorLayout
右下角。
從浮動操作按鈕xml
代碼中刪除android:layout_gravity="bottom|end"
......它會起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.