2013-03-20 14 views
2

因此,我面臨的問題不是主觀地判斷什麼對用戶來說是最好的(我認爲),而是可以用什麼選項來說明定位。Android應用程序中用於佈局的最友好的選項應用

想想某種類型的團隊運動應用程序,您可以在其中爲玩家設置小點(然後我可以用一些代表玩家的UI組件替換點),例如pitch with player initials,您可以在其中拖放紅色和藍點

我試過這與一個gridview,這是非常困難的,因爲我需要有一定數量的行/列,並且他們不擴展,當你在一個更大的分辨率的手機,所以開始黑客攻擊一個「自定義組件」,這感覺就像我在重新發明輪子。

有沒有比寫我自己的組件更好的選擇?

如果這有什麼差別,我米使用xamarin.android

回答

6

我會實現這個使用針對收集綁定的FrameLayout MvvmCross數據綁定。

該方法的核心使用子View中的TranslationXTranslationY屬性,父子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