Xamarin表格TableView默认填充

时间:2017-06-02 01:46:58

标签: xaml xamarin.forms tableview

我想在TableView中添加ViewCell和SwitchCell。我想知道SwitchCell的默认边距是什么,所以我可以让TableView看起来很漂亮。你能救我吗?

    <TableView Intent="Form">
        <TableRoot>
            <TableSection>
                <ViewCell>
                    <StackLayout Padding="?, ?, ?, ?">
                        <!-- Something-->
                    </StackLayout>
                </ViewCell>
                <SwitchCell Text="Something"/>
            </TableSection>
        </TableRoot>
    </TableView>

2 个答案:

答案 0 :(得分:2)

您可以使用Grid而不是ViewCell。试试这个

    <TableView Intent="Form">
        <TableRoot>
            <TableSection>
                <Grid>
                   <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*" />
                     <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
                    <StackLayout Grid.Column="0" Padding="?, ?, ?, ?">
                        <!-- Something-->
                    </StackLayout>
                    <SwitchCell Grid.Column="1" Text="Something"/>
                </Grid>                    
            </TableSection>
        </TableRoot>
    </TableView>

答案 1 :(得分:0)

在iOS上用于视图单元的自定义渲染器中,您可以访问TableViewTableView在分隔符的插入处具有一个SeparatorInset值,该值很容易与我们为视图单元格所需的边距相同。

这似乎对我在iOS 12.2上尝试过的所有iPhone模拟器图像(SE,iPhone XR,iPhone XS)都有效。

public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
    var inset = tv.SeparatorInset.Left;
    var viewCell = (ViewCell) item;

    viewCell.View.Margin = new Thickness(inset, 0, inset, 0);

    return base.GetCell(item, reusableCell, tv);
}