我正在构建一个应用程序,并且有一个配置文件片段,显示配置文件背景图像和一些其他元素.如下面的截图:
我的问题是:为什么AppBarLayout结束时会有额外的底部填充?
这是这个片段的xml布局文件(我基本上是从Cheesesquare复制的):
<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:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<ImageView
android:id="@+id/profile_bg"
android:layout_width="match_parent"
android:layout_height="@dimen/height_profile_background_max"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@id/avatar"
android:layout_width="@dimen/avatar_size_large"
android:layout_height="@dimen/avatar_size_large"
android:layout_marginStart="@dimen/horizontal_padding_normal"
app:civ_border_width="2dp"
app:civ_border_color="@android:color/white"
app:civ_border_overlay="false"
app:layout_constraintTop_toBottomOf="@id/profile_bg"
app:layout_constraintBottom_toBottomOf="@id/profile_bg"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@id/user_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/vertical_padding_small"
android:layout_marginStart="@dimen/horizontal_padding_normal"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:textColor="@color/text_color_normal"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/vertical_padding_small"
android:paddingBottom="@dimen/vertical_padding_normal"
android:layout_marginStart="@dimen/horizontal_padding_normal"
android:textSize="@dimen/text_size_small"
android:textColor="@color/text_color_normal"
android:maxLines="5"
app:layout_constraintTop_toBottomOf="@id/user_display_name"
app:layout_constraintStart_toStartOf="parent"
/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/vertical_divider_height"
android:background="@color/divider_background_color" …Run Code Online (Sandbox Code Playgroud) 我需要一个视图显示在我的应用程序的顶部,当它显示时,它可以继续显示在我所有应用程序的其他视图(所有片段和活动)的顶部。这听起来像一个浮动操作按钮,但会始终显示在我的应用程序的顶部。
我知道我可以通过向手机的 WindowManager 添加视图来实现,并在退出应用程序时隐藏它,在恢复应用程序时再次显示它。这种棘手的方法可以工作,但它也需要一些额外的许可,这是我试图避免的。
如果我只想在我的应用程序中显示,我可以在不征得用户额外许可的情况下实现吗?如果答案是肯定的,那么如何呢?关键似乎是视图的一些 LayoutParams,我尝试过但失败了。
如果答案可以显示一些详细的代码和解释,那就太好了。