程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定?

开发过程中遇到Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定的问题如何解决?下面主要结合日常开发的经验,给出你关于Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定的解决方法建议,希望对你解决Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定有所启发或帮助;

我已经在 xml 中实现了数据绑定,我想将 layoutDirection 设置为我的线性布局,但它会导致如下错误。

这是我的代码

<linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:BACkground="?attr/colorSecondaryVariant"
        androID:orIEntation="horizontal"
        androID:layoutDirection='@{type.equalsIgnoreCase("sell") ? "rtl" : "ltr" }'
        androID:baselineAligned="false"></linearlayout>

这是错误

Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定

解决方法

导入 LayoutDirectionandroid:layoutDirection 期望 LayoutDirection)而不是将字符串传递到布局方向。

<import type="android.util.LayoutDirection"/> 

将 XML android:layoutDirection 改成这样

android:layoutDirection='@{type.equalsIgnoreCase("sell") ? LayoutDirection.RTL : LayoutDirection.RTL }'
,

您可以在此用例中使用 BindingAdapter


@BindingAdapter("changeLayoutDirection")
fun changeLayoutDirection(layout: LinearLayout,direction: String) {
     
  // Write your code here for direction change

}

在您的 xml 中,添加:


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:BACkground="?attr/colorSecondaryVariant"
        android:orientation="horizontal"
        changeLayoutDirection="@{typE}"
        android:baselineAligned="false"></Linearlayout>

大佬总结

以上是大佬教程为你收集整理的Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定全部内容,希望文章能够帮你解决Kotlin - 将 layoutDirection 设置为 linearlayout 错误绑定所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。