我會實現這個使用針對收集綁定的FrameLayout MvvmCross數據綁定。
該方法的核心使用子View
中的TranslationX
和TranslationY
屬性,父子FrameLayout
中包含父屬性。
父是:
<?xml version="1.0" encoding="utf-8"?>
<pointsongrid.BindableFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/points.on.grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource Points"
local:MvxItemTemplate="@layout/item"/>
列表項是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/points.on.grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="TranslationX X, Converter=X;TranslationY Y, Converter=Y"
>
<LinearLayout
android:layout_width="20dp"
android:layout_height="20dp"
local:MvxBind="BackgroundColor Color, Converter=NativeColor"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Text Player"
/>
</LinearLayout>
整個代碼是有點長的StackOverflow,所以我貼了快速回購展示 - https://github.com/slodge/MvvmCross-Players - 數據綁定的FrameLayout有可能肯定會得到改進 - 如果您需要支持更改列表(例如ObservableCollection),請參閱主MvvmCross回購中的LinearLayout代碼以獲取一些想法。
結果看起來有點像:
![enter image description here](https://i.stack.imgur.com/NhJ1Q.png)