मैं कस्टम दृश्य (एक संभव उपयोग जॉर्ज माउंट दिखाया here) के साथ डेटा बाइंडिंग का उपयोग करने की कोशिश कर रहा हूँ।एंड्रॉयड डेटा बाइंडिंग <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
: app:isGone="@{!data.isViewVisible}"
से मैं पूरे परिसर को देखने की दृश्यता को नियंत्रित
<?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>
संकलक त्रुटियों के लिए आशा व्यक्त की:
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}').
मैं सभी neede है डी @BindingAdapter
विधियों। अब मैं FrameLayout
से दृश्य प्राप्त करता हूं और <merge>
के बजाय <RelativeLayout>
का उपयोग करता हूं - और यह काम करता है। लेकिन मेरे पास अतिरिक्त घोंसला वाला लेआउट है।
प्रश्न:merge
attrs अनदेखा कर रहे हैं। क्या काम करने का कोई तरीका है?
एंड्रॉयड स्टूडियो 1.5.1 स्थिर
Gradle प्लगइन com.android.tools.build:gradle:1.5.0
यह अगर तुम बजाय का उपयोग सबसे अच्छा है। –
@ रेकबी राजभांदरी, हां, डाटाबेसिंग ' 'टैग के साथ ठीक काम करता है। हालांकि, यह कस्टम व्यू को बढ़ाने के दौरान अतिरिक्त व्यूग्रुप की समस्या का समाधान नहीं करेगा। –
कृपया मेरे प्रश्न पर एक नज़र डालें। मैं टैग और आंतरिक कक्षा का उपयोग कर रहा हूँ। https://stackoverflow.com/q/45143721/5214893 –