2017-10-05 23 views
0

我想設置視圖以下屬性:無法找到屬性的android二傳手:layout_toRightOf

android:layout_toRightOf="@{}" 

數據綁定。我明白android會轉換camelCase中每個視圖的id。當我做

<RelativeLayout> 

    <TextView 
    android:layout_toRightOf="@{layoutFlag ? myButton : myImageButton }" 
    /> 

    <Button 
    android:id="@+id/my_button"/> 

    <ImageButton 
    android:id="@+id/my_image_button"/> 

</RelativeLayout> 

,但我得到了以下錯誤:

Error:(79, 45) Cannot find the setter for attribute 'android:layout_toRightOf' with parameter type android.view.View on android.widget.TextView. 

回答

0

嘗試傳遞ID○視圖,而不是實際的看法。

@ {layoutFlag? 「+ @ id/my_button」:「+ @ id/my_image_button」}

+0

不起作用 – Thalatta

0

看來你錯過了對象的引用。你的語句應該看起來更像是:

android:layout_toRightOf="@{layoutFlag ? yourClass.myButton : yourClass.myImageButton }" /> 

有了這個佈局文件:

<data> 
     <variable name="yourClass" type="com.example.YourClass"/> 
    </data> 

請審查Data Binding

https://developer.android.com/topic/libraries/data-binding/index.html

的Android文檔很難真正給用您提供的有限代碼詳細回答。

相關問題