Tôi đang sử dụng khung MVVM cho ứng dụng Android có thư viện ràng buộc dữ liệu.Android bao gồm bố cục động với thư viện ràng buộc dữ liệu
Tôi có một số compoment có thể tái sử dụng, nên có mọi hoạt động. f.e. thanh công cụ, menu, nút tác vụ nổi.
Tôi muốn tạo một hoạt động chung, sẽ thực hiện tất cả các tính năng có thể tái sử dụng này và sau đó mọi lớp hoạt động sẽ được kế thừa từ hoạt động chung này. Tôi cũng có lớp GenericViewModel và mọi ViewModel khác được kế thừa từ lớp chung này.
Nhưng tôi gặp sự cố với bố cục. Tôi muốn tạo file layout chung và bao gồm sublayout dinamically. f.e.
<?xml version="1.0" encoding="utf-8"?>
<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">
<data>
<variable
name="data"
type="com.mypackage.genericViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
bind:data="@{data}"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="@{Here i want to have dynamic variable}"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout></layout>
Tôi không muốn sao chép/dán mã này cho từng hoạt động, nhưng thư viện ràng buộc dữ liệu không cho phép bao gồm bố cục động. Có giải pháp nào cho những trường hợp như vậy không?
Cảm ơn, nó rất hữu ích cho tôi –