1
我有一個View
,此視圖包含一個Point
。我想將數據綁定到這一點,但據我所知,我無法在attrs.xml
中創建一個自定義屬性,其格式爲Point
。將自定義視圖綁定到點
這是視圖:
public class MyView extends android.support.v7.widget.AppCompatImageView {
private Point point;
public MyView(Context context) {
super(context);
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
}
這是爲MyObject:
public class MyObject extends BaseObservable {
private Point point;
@Bindable
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
notifyPropertyChanged(BR.point);
}
}
現在我要綁定MyView的是這樣的:
<MyView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:point="@{myObject.point}"/>
和attrs.xml
文件像這樣:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView">
<attr name="point" format="Point" />
</declare-styleable>
</resources>
但這似乎不可能。有人知道解決方案嗎?