【问题标题】:Android Set Bottom Sheet State in XMLAndroid 在 XML 中设置底部工作表状态
【发布时间】:2019-04-15 03:32:20
【问题描述】:

XML 中的底部工作表有几种状态:STATE_COLLAPSED、STATE_EXPANDED、STATE_HIDDEN 等。

如何使用 observable 在 XML 中设置集合?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_sheet_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:behavior_hideable="true"
    app:behavior_peekHeight="0dp"
    app:layout_behavior="@string/bottom_sheet_behavior"
    <!-- Example of State -->
    app:bottom_state="@{viewModel.state}"
    >
</LinearLayout>

显然,底部状态的名称不正确,但我想弄清楚是什么。

【问题讨论】:

    标签: android android-layout bottom-sheet


    【解决方案1】:

    没有可用于底部工作表状态的直接 xml 值。但是如果你想在数据绑定中做到这一点,还有另一种选择。为此创建一个绑定适配器并使用它。

    @BindingAdapter("bottomSheetState")
    fun bindingBottomSheet(container: LinearLayout, state:Int) {
        val behavior=BottomSheetBehavior.from(container)
        behavior.state = state
    }
    

    现在可以在xml中使用了

    <LinearLayout
        android:layout_height="340dp"
        android:layout_width="match_parent"
        app:behavior_hideable="true"
        app:behavior_peekHeight="80dp"
        app:bottomSheetState="@{model.uiState.bottomSheetState}"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
    

    【讨论】:

      猜你喜欢
      • 2020-04-16
      • 1970-01-01
      • 2019-10-19
      • 2018-10-28
      • 1970-01-01
      • 2020-12-11
      • 2016-10-05
      • 2016-12-27
      • 1970-01-01
      相关资源
      最近更新 更多