2017-04-04 70 views
1

我想知道如何使項目分開,而不是非常接近對方。現在,iOS上的每個項目都太靠近了。 我嘗試在ListView和StackLayout上設置邊距和空間,但每個項目之間的空間沒有改變。爲了增加空間,我發現我需要對圖像單元做些什麼。圖像單元是從文本單元繼承的,但沒有屬性設置邊距或空間。有誰知道如何操作?如何在MasterDetail頁面上的項目之間添加空格?

public MasterPageCS() 
{ 
    var masterPageItems = new List<MasterPageItem>(); 
    masterPageItems.Add (new MasterPageItem { 
     Title = "Contacts", 
     IconSource = "contacts.png", 
     TargetType = typeof(ContactsPageCS) 
    }); 
    masterPageItems.Add (new MasterPageItem { 
     Title = "TodoList", 
     IconSource = "todo.png", 
     TargetType = typeof(TodoListPageCS) 
    }); 
    masterPageItems.Add (new MasterPageItem { 
     Title = "Reminders", 
     IconSource = "reminders.png", 
     TargetType = typeof(ReminderPageCS) 
    }); 

    listView = new ListView { 
     ItemsSource = masterPageItems, 
     ItemTemplate = new DataTemplate (() => { 
      var imageCell = new ImageCell(); //This one!!!! 
      imageCell.SetBinding (TextCell.TextProperty, "Title"); 
      imageCell.SetBinding (ImageCell.ImageSourceProperty, "IconSource"); 
      return imageCell; 
     }), 
     VerticalOptions = LayoutOptions.FillAndExpand, 
     SeparatorVisibility = SeparatorVisibility.None 
    }; 

    Padding = new Thickness (0, 40, 0, 0); 
    Icon = "hamburger.png"; 
    Title = "Personal Organiser"; 
    Content = new StackLayout { 
     VerticalOptions = LayoutOptions.FillAndExpand, 
     Children = { 
      listView 
     } 
    }; 
} 

回答

2

有一個人問類似的問題:link

使用ViewCell,這樣你可以控制佈局和間距,內置的佈局模板只對基本的東西是有用的。

這裏有一個樣品使用ViewCell。

Adding padding inside ViewCell xamarin

我的建議是使用網格對在可能情況下,更好的性能和更少的麻煩跨平臺自定義佈局,stacklayouts可以的DataTemplates導致問題的iOS尤其是高度爲自動。

如果使用TextCell &的ImageCell然後形成需要幫助您的最佳猜測。

另外,如果你使用網爲您MasterPageItem孩子,設置RowSpacing爲0的電網,只有這樣,你的數據模板設置頁邊距開始按照您的預期工作。

相關問題