【发布时间】:2019-11-22 05:28:35
【问题描述】:
我见过两种使用数据绑定在 XML 中设置可见性的方法
-
<variable name="vm" type="com.example.myapp.viewmodel.MyViewmodel" /> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar style="@style/ProgressBarMediumWhite" android:visibility="@{vm.showLoader ? View.VISIBLE : View.GONE}" /> -
<variable name="vm" type="com.example.myapp.viewmodel.MyViewmodel" /> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar style="@style/ProgressBarMediumWhite" android:visibility="@{vm.showLoader}" />
我想知道哪种方法更好,或者两者似乎都很好。 将android视图导入XML文件有多糟糕。
【问题讨论】:
标签: android android-layout android-databinding androidx