我制作了一個應(yīng)用程序,其中一個活動包含兩個 TextView、一個 ImageView 和 FloatingActionButton。我想做這樣的布局。這是我的代碼。<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:fillViewport="true" tools:context=".DetailsActivity" android:id="@+id/scrollView" > <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- <ProgressBar android:id="@+id/progressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> --> <TextView android:id="@+id/titleTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:textSize="25sp" android:textStyle="bold" /> <TextView android:id="@+id/blogContent" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" android:textSize="16sp" /> <ImageView android:id="@+id/youtubeThumbnailImage" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="20dp" android:src="@mipmap/ic_launcher" android:visibility="gone" />這適用于android 6.0。但高于 6.0,浮動按鈕出現(xiàn)在活動的右上角。
1 回答

慕的地10843
TA貢獻1785條經(jīng)驗 獲得超8個贊
使用 CoordinatorLayout,您應(yīng)該嘗試將 FloatingActionButtons 錨點設(shè)置為引用 LinearLayout 并layout_anchorGravity用于定位 FAB。
您的 FAB 的示例代碼:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/linearLayoutID"
app:layout_anchorGravity="bottom|right|end"
android:layout_margin="16dp"
android:src="@drawable/icons8_share_480"
/>
記得為你的 LinearLayout 設(shè)置一個 ID。我用作@id/linearLayoutID占位符。
添加回答
舉報
0/150
提交
取消