【发布时间】:2020-02-06 02:26:50
【问题描述】:
我正在尝试在 Android 的底页上制作 静态页脚。下面是我当前尝试的 GIF。当工作表完全展开时,请注意工作表底部的 footer 文本。无论工作表处于何种状态,我都希望此页脚文本始终显示。(例如,如果工作表仅展开一半,页脚仍应显示。当工作表展开/折叠时,页脚仍应始终显示等)我怎样才能完成这种行为?我看过这个:https://github.com/umano/AndroidSlidingUpPanel,但我更愿意得到一个不涉及任何外部库的 vanilla android 解决方案。
这是我当前的 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>
这是我的片段的样子。它只是一个显示底部工作表的空白片段:
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而不是底页。在Dialogs 上,保持静态页脚非常容易。真的很想知道它是否可以在底片上。
标签: android android-layout android-fragments bottom-sheet