私はカスタムビューでデータバインディングを使用しようとしています(George Mountが示した可能性のある使用here)。Androidのデータバインディングが<merge>属性で動作していません
<merge>
タグなしで建物の複合ビューを想像することはできません。しかし、このような状況のデータバインディングに失敗します。
MyCompoundView
クラス:
public class MyCompoundView extends RelativeLayout {
MyCompoundViewBinding binding;
public MyCompoundView (Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
binding = MyCompoundViewBinding.inflate(inflater, this, true);
}
my_compound_view.xml
:私は、化合物全体のビューの表示を制御
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<data>
<variable name="data" type="com.example.MyViewModel"/>
</data>
<merge
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:isGone="@{!data.isViewVisible}">
<ImageView
android:id="@+id/image_image"
android:layout_width="60dp"
android:layout_height="60dp"
app:imageUrl="@{data.imagePhotoUrl}"/>
<!-- tons of other views-->
</merge>
</layout>
コンパイルエラーすることを望んだapp:isGone="@{!data.isViewVisible}"
によって:
Error:(13) No resource identifier found for attribute 'isGone' in package 'com.example'
Error:(17, 21) No resource type specified (at 'isGone' with value '@{!data.isViewVisible}').
私はすべてが必要です方法。今私はFrameLayout
からの見解を継承し、<merge>
の代わりに<RelativeLayout>
を使用して動作します。しかし、私は追加のネストされたレイアウトを持っています。
質問:merge
attrsは無視されます。回避策はありますか?
のAndroid Studioの1.5.1安定
のGradleプラグインcom.android.tools.build:gradle:1.5.0
@Rakeeb Rajbhandari、はい、データバインディングは ''タグでうまくいきます。ただし、カスタムビューを拡張しているときに、これにより余分なビューグループの問題は解決されません。 –
私の質問を見てください。私はincludeタグと内部クラスを使用しています。 https://stackoverflow.com/q/45143721/5214893 –