【发布时间】:2021-05-29 15:11:07
【问题描述】:
在我的片段中,我使用底部表格来显示一些 UI 组件
这是我的片段 xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
>
<!-- other views -->
<include
android:id="@+id/feedbackIncluded"
layout="@layout/chat_feedback" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我目前从我的片段中处理底部表的视图操作或数据。
我打算将用于底页处理的代码分离到另一个类
这是我的底部工作表 xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:behavior_hideable="false"
app:behavior_peekHeight="16dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/parentSheetLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<!-- some views -->
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
这是我创建的要处理的类
class ChatFeedbackBottomSheet(context: Context) {
var binding: ChatFeedbackBinding? = null
init {
binding = ChatFeedbackBinding.inflate(LayoutInflater.from(context), null, false)
println(binding?.option1.text)
}
fun openSheet() {
println("------>" + binding?.option1?.text)
}
}
我似乎不知道如何在此类中获得正确的视图绑定对象?
【问题讨论】:
标签: android data-binding android-viewbinding