Bry*_*yan 7 xamarin xamarin.forms
我正在使用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>
Run Code Online (Sandbox Code Playgroud)
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 },
},
},
};
Run Code Online (Sandbox Code Playgroud)
要在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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
只需将此类复制到您的Android项目中,您就可以了.
归档时间: |
|
查看次数: |
3222 次 |
最近记录: |