如果有人有更好的解决方案,我几天内不会将此标记为可接受的答案。我愿意接受建议,因为如果我必须在这个“表”中添加另一列,这个解决方案就行不通了。
截至今天(2016 年 6 月 11 日),我不得不说 TableView 的问题太多,不实用。对额外空间的抱怨一直存在,当您触摸文本视图时,它们看起来就像要执行一个动作(没有视频很难解释)。它们是静态文本,不应响应触摸。
这是我制作简单的两列表格的方法(尽管它更像是表格视图而不是传统表格)。悬崖笔记?一个垂直方向的 StackLayout 中的几个水平方向的 StackLayout。我将一个标签放在最左边,另一个放在最右边。最终结果如下所示:
//Result Items
/* Start chest */
Label txtChest = new Label
{
Text = "Chest",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtChestResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End chest */
/* Start Biceps */
Label txtBiceps = new Label
{
Text = "Biceps",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtBicepsResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Biceps */
/* Start Forearms */
Label txtForearms = new Label
{
Text = "Forearms",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtForearmsResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Forearms */
/* Start Neck */
Label txtNeck = new Label
{
Text = "Neck",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtNeckResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Neck */
/* Start Thighs */
Label txtThighs = new Label
{
Text = "Thighs",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtThighsResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Thighs */
/* Start Calves */
Label txtCalves = new Label
{
Text = "Calves",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtCalvesResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Calves */
//Chest StackLayout
StackLayout chestLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
chestLayout.Children.Add(txtChest);
chestLayout.Children.Add(txtChestResults);
//biceps layout
StackLayout bicepsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
bicepsLayout.Children.Add(txtBiceps);
bicepsLayout.Children.Add(txtBicepsResults);
//forearms layout
StackLayout forearmsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
forearmsLayout.Children.Add(txtForearms);
forearmsLayout.Children.Add(txtForearmsResults);
//Neck layout
StackLayout neckLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
neckLayout.Children.Add(txtNeck);
neckLayout.Children.Add(txtNeckResults);
//Thighs layout
StackLayout thighsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
thighsLayout.Children.Add(txtThighs);
thighsLayout.Children.Add(txtThighsResults);
//Calves layout
StackLayout calvesLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
calvesLayout.Children.Add(txtCalves);
calvesLayout.Children.Add(txtCalvesResults);
StackLayout resultsLayout = new StackLayout
{
Orientation = StackOrientation.Vertical
};
resultsLayout.Children.Add(chestLayout);
resultsLayout.Children.Add(bicepsLayout);
resultsLayout.Children.Add(forearmsLayout);
resultsLayout.Children.Add(neckLayout);
resultsLayout.Children.Add(thighsLayout);
resultsLayout.Children.Add(calvesLayout);
//add chest results
layout.Children.Add(resultsLayout);