android - 在工具栏上方显示粘滞按钮
问题描述
我有以下布局:
<LinearLayout
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:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="@style/Toolbar"/>
<com.sample.android.scrolltricks.ObservableScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView style="@style/Item"
android:scaleType="centerCrop"
android:src="@drawable/london_flat"
tools:ignore="contentDescription"/>
<View android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="@dimen/sticky_height"/>
<View style="@style/Item.Bottom"/>
<View style="@style/Item.Bottom.Alt"/>
<View style="@style/Item.Bottom"/>
<View style="@style/Item.Bottom.Alt"/>
<View style="@style/Item.Bottom"/>
<View style="@style/Item.Bottom.Alt"/>
</LinearLayout>
<Button android:id="@+id/sticky" style="@style/Sticky"/>
</FrameLayout>
</com.sample.android.scrolltricks.ObservableScrollView>
</LinearLayout>
这是滚动时显示粘滞按钮的代码:
override fun onScrollChanged(scrollY: Int) {
sticky.translationY = Math.max(
placeholder.top - resources.getDimension(R.dimen.sticky_height) / 2,
scrollY.toFloat() - 65
)
}
粘性按钮显示在工具栏下方,我想将其部分显示在工具栏上方。( scrollY.toFloat() - 65
)
你知道怎么解决吗?
解决方案
不幸的是,在您的布局中,您无法将其Button
置于ScrollView
. 你Button
是 的孩子FrameLayout
,它是它ScrollView
自己的孩子,因此它的绘图区域受到父母的界限的限制。
最好通过包装所有内容来解决此类任务,CoordinatorLayout
然后CoordinatorLayout.Behavior
在View
您想要具有特定定位的对象上应用自定义。
希望能帮助到你。
推荐阅读
- json - Kibana CSV 导出失败,包含 JSON 数据
- xcode - 从 xcodebuild 命令行工具设置 DerivedData 路径
- mysql - To count and return multiple row in single sql query and print result as table
- python - 如何保持 Python 脚本运行以继续读取文本文件?
- .net - 如何在 Active Reports 15 中显示特定项目的特定图像
- c - Rust cdylib crate,将 dll 链接到 Windows 中的 C 程序
- php - 如何序列化布尔值?
- python - 如何在 Python 中更改网格的 UP-Vector?
- gpu - Pytorch Lightning 完全在 gpu 上使用小数据集进行训练
- java - Sonar:用方法引用替换这个 lambda。什么时候应该使用“stream()”?