我正在使用Xamarin.Forms
,目前正在尝试制作没有节标题的TableView
。现在iOS
这看起来很好,因为部分标题不可见或无法点击,但在Android
上标题是空白,可见和可点击的。
我试过这个http://forums.xamarin.com/discussion/18037/tablesection-w-out-header
xaml中的代码 -
<TableView>
<TableView.Root>
<TableSection>
<TextCell Text="Login" Command="{Binding Login}" />
<TextCell Text="Sign Up" Command="{Binding SignUp}" />
<TextCell Text="About" Command="{Binding About}"/>
</TableSection>
</TableView.Root>
</TableView>
c#中的代码
Content = new TableView
{
Root = new TableRoot
{
new TableSection ()
{
new TextCell { Text="Login", Command = Login },
new TextCell { Text="Sign Up", Command = SignUp },
new TextCell { Text="About", Command = About },
},
},
};
答案 0 :(得分:7)
要在Android上取消标头,我们会使用自定义渲染器。如果Text
为空,则会通过删除所有子项来隐藏单元格,从而降低高度并删除所有填充。
[assembly: ExportRenderer(typeof(TextCell), typeof(ImprovedTextCellRenderer))]
namespace YourSolution.Android
{
public class ImprovedTextCellRenderer : TextCellRenderer
{
protected override global::Android.Views.View GetCellCore(Cell item, global::Android.Views.View convertView, ViewGroup parent, Context context)
{
var view = base.GetCellCore(item, convertView, parent, context) as ViewGroup;
if (String.IsNullOrEmpty((item as TextCell).Text)) {
view.Visibility = ViewStates.Gone;
while (view.ChildCount > 0)
view.RemoveViewAt(0);
view.SetMinimumHeight(0);
view.SetPadding(0, 0, 0, 0);
}
return view;
}
}
}
只需将此类复制到您的Android项目中,您就可以了。