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>
但这似乎不可能。有人知道解决方案吗?