我正在尝试在Android的bottomsheet上制作一个静态页脚。下面是我当前尝试的GIF。请注意,当它完全展开时,在页面底部的
这是我的fragment样式。它只是一个空白的fragment,显示底部sheet:
这是我的片段布局:
footer
文本。我希望这个页脚文本无论表格处于什么状态都能始终显示。(例如,如果表格只展开了一半,页脚仍应该显示。随着表格的展开/折叠,页脚仍然应该始终显示等。) 我该如何实现这种行为?我已经看过了这个:https://github.com/umano/AndroidSlidingUpPanel 但我更喜欢得到一个不涉及任何外部库的原生安卓解决方案。
这是我的当前XML。我认为问题在于页脚被锚定在视图底部,但只有在表格完全展开时才能看到视图底部。我想知道是否可以让页脚在任何状态下都显示:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:airbnb="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:id="@+id/linear_layout_container">
<TextView
android:id="@+id/header_text"
android:layout_width="match_parent"
android:text="Header"
android:layout_height="36dp"
android:layout_alignParentTop="true"
/>
<com.airbnb.epoxy.EpoxyRecyclerView
android:id="@+id/bottom_sheet_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
airbnb:layoutManager="LinearLayoutManager"
android:layout_above="@+id/footer_text"
android:layout_below="@+id/header_text"
/>
<TextView
android:id="@+id/footer_text"
android:layout_width="match_parent"
android:text="Footer"
android:layout_height="36dp"
android:layout_alignParentBottom="true"
airbnb:layout_anchorGravity="bottom"
/>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
这是我的fragment样式。它只是一个空白的fragment,显示底部sheet:
ContainerFragment.kt
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.epoxy.EpoxyRecyclerView
import com.google.android.material.bottomsheet.BottomSheetDialog
class ContainerFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.container_fragment_layout, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.alpha = 0f
val bottomSheet = BottomSheetDialog(requireContext())
val bottomSheetView = LayoutInflater.from(context).inflate(R.layout.test_bottom_sheet_layout, null)
bottomSheet.setContentView(bottomSheetView)
bottomSheet.show()
val epoxyRecyclerView : EpoxyRecyclerView = bottomSheetView.findViewById(R.id.bottom_sheet_recycler_view)
epoxyRecyclerView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
epoxyRecyclerView.withModels {
(0..100).forEach {
basicRow {
id(it)
title("This is the entry at index $it.")
}
}
}
}
companion object {
fun newInstance() = ContainerFragment()
}
}
这是我的片段布局:
container_fragment_layout.xml
:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Dialog
而不是底部工作表。在Dialog
上,保持静态页脚非常容易。但我真的很想知道在底部工作表上是否也可能实现这一点。 - Ryan