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>
しかし、これは可能ではないようです。誰かが解決策を知っていますか?