[英]Android data binding with include tag doesn't work
我正在使用 android 數據綁定,只要我不使用包含標簽,它就可以正常工作。
如果我使用了一個視圖標記(即使它顯示在應用程序上)但數據綁定對象無法識別包含的布局的視圖。 這些是我的布局文件。
internet_unavailable.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/internet_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_horizontal"
android:text="@string/msg_internet_unavailable"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/colorSecondaryText" />
<Button
android:id="@+id/internet_button_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/internet_margin_top"
android:backgroundTint="@color/colorAccent"
android:paddingEnd="@dimen/internet_padding_h"
android:paddingStart="@dimen/internet_padding_h"
android:text="@string/str_retry"
android:textColor="@android:color/white" />
</LinearLayout>
</layout>
片段.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ncimsl.fragments.ProgressNotesFragment">
<include
android:id="@+id/progress_notes_internet"
layout="@layout/internet_unavailable" />
<ProgressBar
android:id="@+id/progress_notes_progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/progress_notes_swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/progress_notes_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</layout>
如您所見,progressBar、swipeRefreshLayout 和 recyclerView 顯示在建議中,除了包含的布局和其中的視圖。
有什么想法可以解決這個問題嗎?
想與那些仍在掙扎的人分享我的經驗......我遇到了同樣的問題,直到在應用程序的 build.gradle 中打開viewBinding (除了dataBinding )才解決。 (Android Studio 4.2
buildFeatures {
dataBinding = true
viewBinding = true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.