我在底页上有以下代码
xml文件
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="@+id/titleTextview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:fontFamily="sans-serif"
android:text="@string/choose_option"
android:textColor="@android:color/darker_gray"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintBottom_toTopOf="@id/recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleTextview" />
</androidx.constraintlayout.widget.ConstraintLayout>
查看
class AttributeOptionsBottomSheet(val viewModel: AttributeOptionsViewModel) : BottomSheetDialogFragment() {
override fun getTheme(): Int = R.style.AppBottomSheetDialogTheme
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.bottom_sheet_attributes, container, false)
.also { view ->
view.findViewById<RecyclerView>(R.id.recyclerView).apply {
context?.let {
layoutManager = LinearLayoutManager(Activity())
adapter = AttributeOptionsAdapter(viewModel)
viewModel.dismissView.observe({ lifecycle }) {
dismiss()
}
}
}
}
}
查看模型
class AttributeOptionsViewModel(attributeId: Int) : BaseViewModel() {
val optionsDao: ExtraAttributeOptionDao by inject()
var options : List<ExtraAttributeOptionEntity> = ArrayList<ExtraAttributeOptionEntity>()
val dismissView = LiveEvent<Unit>()
var optionSelected = LiveEvent<ExtraAttributeOptionEntity>()
init {
getOptions(attributeId)
}
fun getOptionName(position: Int): String {
return options[position].name
}
fun setSelectedOption(position: Int) {
options[position].apply {
optionSelected.postValue(this)
dismissView.postValue(Unit)
}
}
fun getOptions(attributeId: Int) {
launch(Dispatchers.IO) {
options = optionsDao.getExtraAttributeOptionsBuAttributeId(attributeId)
}
}
}
我的问题是,只有少量项目时才显示底部表格,而没有大量项目时则显示底部表格,屏幕仅变暗且无任何反应
任何人都可以帮忙吗?
答案 0 :(得分:1)
由于我不确定它是否是唯一的解决方案,所以我还没有使用它。
将您的.errorTransition-enter {
opacity: 0.01;
}
.errorTransition-enter-active {
opacity: 1;
transition: all 400ms ease-out;
}
.errorTransition-exit {
opacity: 1;
}
.errorTransition-exit-active {
opacity: 0.01;
transition: all 400ms ease-out;
}
的高度更改为RecyclerView
然后将以下几行添加到您的wrap_content
TextView
或从app:layout_constraintVertical_bias="0"
app:layout_constraintVertical_chainStyle="packed"
中删除bottom constraint
并将相同的TextView
添加到bias
对我有用。