c#中xamarin怎么添加包

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#中xamarin怎么添加包相关的知识,希望对你有一定的参考价值。

参考技术A 1.在解决方案中添加android绑定库
2.新建的项目中,有一个Jars文件夹,右键该文件夹,新建现有项,在弹出的选择框中选择你要引入的jia包(不需要拷贝进来)
3.等待片刻,引入成功,会发现jar包有刚引入的jar包,
4.点击该jar包,把生成操作改成'EmbeddedJar,然后编译该项目
5.在你的安卓主项目中引入刚刚新建的Android绑定库项目,就可以正常使用jar包里的方法啦,而且发现方法已经转成了C#代码,但注意原来jar包中的方法名和类名在转成C#后,首字母可能会变成大写.

使用 xamarin.ios c# 以编程方式添加嵌套的堆栈视图

【中文标题】使用 xamarin.ios c# 以编程方式添加嵌套的堆栈视图【英文标题】:Adding nested stackviews programmatically using xamarin.ios c# 【发布时间】:2018-06-14 08:45:30 【问题描述】:

我正在使用 xamarin 和 mvvmcross 为 android 和 ios 创建一个应用程序。 在 ios 应用程序中,我想添加具有嵌套水平堆栈视图的外部垂直堆栈视图。基本上我只想创建一个基本的人员详细信息屏幕,其中左侧是标签,右侧是文本字段,它们将进入一个水平堆栈视图,像这样会有许多水平堆栈视图嵌套在外部垂直堆栈视图中。

我正在互联网上寻找这样的示例,但似乎大多数示例都在 swift 中,但我几乎无法在 c# 中找到一些示例。

有人可以帮忙吗。

谢谢, 桑托什

【问题讨论】:

【参考方案1】:

UIStackView 利用 Auto Layout 和 Size Classes 的强大功能来管理水平或垂直的子视图堆栈,这些子视图动态响应 iOS 设备的方向和屏幕大小。你可以通过这个documentation了解它。

在你的情况下,我们可以构造一个垂直堆栈来放置几个水平堆栈:

UIStackView verticalStack = new UIStackView();
View.AddSubview(verticalStack);
verticalStack.Axis = UILayoutConstraintAxis.Vertical;
verticalStack.TranslatesAutoresizingMaskIntoConstraints = false;

// Use auto layout to embed this super vertical stack in the View. Also there's no need to set the height constraint, vertical stack will automatically adjust that depending on its content
verticalStack.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor).Active = true;
verticalStack.TopAnchor.ConstraintEqualTo(TopLayoutGuide.GetBottomAnchor()).Active = true;
verticalStack.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor).Active = true;           

for (int i=0; i<10; i++)

    // Here try to put some horizontal stack with Label on left and textfield on right in the father stack.
    UIStackView horizontalStack = new UIStackView();
    horizontalStack.Distribution = UIStackViewDistribution.EqualSpacing;
    horizontalStack.Axis = UILayoutConstraintAxis.Horizontal;
    // UIStackView should use AddArrangedSubview() to add subviews.
    verticalStack.AddArrangedSubview(horizontalStack);
    UILabel textLabel = new UILabel();
    textLabel.Text = "text";
    UITextField textField = new UITextField();
    textField.Placeholder = "enter text";
    horizontalStack.AddArrangedSubview(textLabel);
    horizontalStack.AddArrangedSubview(textField);

但是如果每个水平堆栈的子视图几乎是相同的样式和布局。为什么不尝试使用UITableView?您只需要设置单个单元格的内容和布局,然后在 tableView 中使用它。此外,此控件可重复使用且可滚动。

【讨论】:

以上是关于c#中xamarin怎么添加包的主要内容,如果未能解决你的问题,请参考以下文章

c#中xamarin怎么连接海康摄像头添加照片

以编程方式将视图添加到 Xamarin.Android C# 中的 GridLayout

使用 xamarin.ios c# 以编程方式添加嵌套的堆栈视图

Xamarin.android如何添加snackbar回调

在 c# Xamarin 中等待带有弹出窗口的任务

异步流在 xamarin (C# 7.3) 中不可用