【问题标题】:Use AsyncLayoutInflater with DataBinding将 AsyncLayoutInflater 与 DataBinding 一起使用
【发布时间】:2018-03-27 15:01:46
【问题描述】:

我目前使用DataBindingUtil.inflate(inflater, layoutId, parent, attachToParent) 方法对我的大部分布局进行膨胀。

但我看到他们是AsyncLayoutInflater,因为Support Library revision 24 允许通货膨胀发生在单独的线程上。我想在我的应用程序的某些部分使用这种机制,但我不想为此放弃使用 databinding

DataBindingUtil 不包含像inflateAsync() 这样的任何方法。但它是否计划增加对此的支持?还是他们将AsyncLayoutInflaterdatabinding 的使用结合起来的一种方式?

我尝试在DataBindingUtilinflate 方法中使用AsyncLayoutInflater,但实际上AsyncLayoutInflater 不是原始LayoutInflater 的子类。

感谢阅读!

【问题讨论】:

    标签: android asynchronous layout-inflater android-databinding


    【解决方案1】:

    您可以只使用DataBindingUtil.bind(view) 绑定到膨胀布局的根。

    new AsyncLayoutInflater(this).inflate(R.layout.my_layout, null, new AsyncLayoutInflater.OnInflateFinishedListener() {
        @Override
        public void onInflateFinished(@NonNull View view, int resid, @Nullable ViewGroup parent) {
            MyLayoutBinding binding = DataBindingUtil.bind(view);
        }
    });
    

    【讨论】:

      【解决方案2】:

      没有办法将AsyncLayoutInflater 与数据绑定一起使用,但我的问题是,它真的有用吗?异步扩展布局有其优势,但如果您正在使用数据绑定,当您尝试将数据绑定到视图时,您将面临视图未扩展的风险,因为没有像 waitForBinding() 这样的方法。

      【讨论】:

        猜你喜欢
        • 2021-08-26
        • 1970-01-01
        • 2020-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-30
        • 1970-01-01
        相关资源
        最近更新 更多