如何解决从 Kotlin 合成转换为数据绑定的问题
我目前正在尝试将应用的布局操作从合成更改为数据绑定。
我遵循了 google 教程,它几乎适用于所有情况,但有一个有点难以解决,欢迎提供帮助。
这是我需要帮助的地方:
在性别选择部分,我有 3 张卡片来选择一个人的性别(男/女/怀孕)。后面是一个值,该值将所选性别保留为 Int(0=女性,1=男性),但是如果我单击怀孕案例,我会打开一个对话框,询问怀孕季度(代码 2、3 和 4)。我的问题是我无法找到适合这种情况的正确组织
有没有人知道他们将如何使用数据绑定来做到这一点?我正在为卡片使用 TextViews,但不要犹豫,建议其他解决方案。
布局 XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/longTopMargin"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/card_man"
android:layout_width="80dp"
android:layout_height="75dp"
android:layout_marginTop="@dimen/baseTopMargin"
android:layout_marginBottom="@dimen/baseTopMargin"
android:background="@drawable/white_rounded_rectangle"
android:elevation="2dp"
android:fontFamily="@font/cera_pro_medium"
android:gravity="center"
android:padding="@dimen/baseTopMargin"
android:text="@string/a_man"
android:textColor="@color/textColorGrey"
android:textSize="@dimen/paragraph_text_size" />
<TextView
android:id="@+id/card_woman"
android:layout_width="80dp"
android:layout_height="75dp"
android:layout_marginStart="@dimen/largeTopMargin"
android:layout_marginTop="@dimen/baseTopMargin"
android:layout_marginBottom="@dimen/baseTopMargin"
android:background="@drawable/white_rounded_rectangle"
android:elevation="2dp"
android:fontFamily="@font/cera_pro_medium"
android:gravity="center"
android:padding="@dimen/baseTopMargin"
android:text="@string/a_woman"
android:textColor="@color/textColorGrey"
android:textSize="@dimen/paragraph_text_size" />
<LinearLayout
android:id="@+id/card_pregnant"
android:layout_width="85dp"
android:layout_height="75dp"
android:layout_marginStart="@dimen/largeTopMargin"
android:layout_marginTop="@dimen/baseTopMargin"
android:layout_marginBottom="@dimen/baseTopMargin"
android:background="@drawable/white_rounded_rectangle"
android:elevation="2dp"
android:gravity="center"
android:orientation="vertical"
android:padding="@dimen/baseTopMargin">
<TextView
android:id="@+id/tv_pregnant_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/cera_pro_medium"
android:gravity="center"
android:text="@string/a_woman"
android:textColor="@color/textColorGrey"
android:textSize="@dimen/paragraph_text_size" />
<TextView
android:id="@+id/tv_pregnant_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/cera_pro_regular"
android:gravity="center"
android:text="@string/a_woman_pregnant"
android:textColor="@color/textColorGrey"
android:textSize="@dimen/paragraph_text_size" />
</LinearLayout>
</LinearLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。