Я пытаюсь создать статический нижний колонтитул на нижнем листе Android. Ниже представлена гифка с моей текущей попыткой. Обратите внимание на текст footer
внизу листа, когда он полностью развернут. Я хочу, чтобы этот текст нижнего колонтитула всегда отображался независимо от того, в каком состоянии находится лист (например, если лист развернут только наполовину, нижний колонтитул все равно должен отображаться. Поскольку лист разворачивается / сворачивается, нижний колонтитул должен всегда отображаться и т. д.) Как я могу добиться такого поведения? Я видел это: https://github.com/umano/AndroidSlidingUpPanel, но я бы предпочел чтобы получить ванильное решение для 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
вместо нижнего листа. НаDialog
s действительно легко сохранить статический нижний колонтитул. Хотелось бы узнать, возможно ли это на нижних листах. - person Ryan   schedule 09.11.2019