我尝试在 Xamarin.Forms 中创建图表,但无法显示。我也想知道我要把这段代码放在哪里。它是在 .xaml 中还是在 .xaml.cs 中?我只是使用 Xamarin 的初学者,所以也许有人可以帮助我。
这是我要使用的代码。
using BarChart;
...
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
var data = new [] { 1f, 2f, 4f, 8f, 16f, 32f };
var chart = new BarChartView (this) {
ItemsSource = Array.ConvertAll (data, v => new BarModel { Value = v })
};
AddContentView (chart, new ViewGroup.LayoutParams (
ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
}
Run Code Online (Sandbox Code Playgroud) 我是 android 开发的新手,需要为我在 Xamarin Studios 中制作的 android 应用程序创建一个 apk 文件,以便我的同行可以在他的设备上测试它。如何创建apk文件?
我是一名业余编码员,试图四处游玩和探索。我的编码水平是相当新手。我一直在尝试在 Xamarin 中构建一个简单的应用程序。它所包含的只是一个加载我网站的 webView。就是这样。当我尝试构建时,出现以下错误,我似乎无法找到答案。有人可以帮忙吗?
严重性代码描述项目文件行抑制状态警告 CS0672 成员“MainActivity.HelloWebViewClient.ShouldOverrideUrlLoading(WebView, string)”覆盖过时的成员“WebViewClient.ShouldOverrideUrlLoading(WebView, string)”。将 Obsolete 属性添加到“MainActivity.HelloWebViewClient.ShouldOverrideUrlLoading(WebView, string)”。pnbApp D:\Workspace\PNB_App\pnbApp\pnbApp\MainActivity.cs 29 活动
这是它在代码中失败的部分:
> public class HelloWebViewClient : WebViewClient
> {
> public override bool ShouldOverrideUrlLoading(WebView view, string url)
> {
> view.LoadUrl(url);
> return true;
> }
> }
Run Code Online (Sandbox Code Playgroud)
提前致谢。
在Xamarin.Forms,在 PCL 中,我有自定义控件,带有自定义事件:
public class TestGrid : Grid
{
public EventHandler OnTapped;
public TestGrid()
{
var tgr = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
tgr.Tapped += Tgr_Tapped;
this.GestureRecognizers.Add(tgr);
}
private void Tgr_Tapped(object sender, EventArgs e)
{
OnTapped?.Invoke(sender, e);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的起始页中,我有:
public partial class StartPage : ContentPage
{
public StartPage()
{
InitializeComponent();
BindingContext = new StartPageViewModel();
MainGrid.OnTapped += OnGridTapped;
}
private void OnGridTapped(object sender, EventArgs e)
{
Debug.WriteLine("Tapped!");
}
}
Run Code Online (Sandbox Code Playgroud)
我的 XAML 看起来像这样,它可以工作:
<v:TestGrid x:Name="MainGrid" />
Run Code Online (Sandbox Code Playgroud)
但! …
我正在尝试通过 ButtonRender 实现 android 按钮的功能。当我尝试加入“.LongClick”和“.touch”时会出现问题,因为它不会启动长按事件。
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
this.SetBackgroundResource(Resource.Drawable.button);
base.OnElementChanged(e);
Android.Widget.Button thisButton = Control as Android.Widget.Button;
thisButton.LongClickable = true;
thisButton.LongClick += delegate
{
string s = "";
};
thisButton.Touch += (object sender, Android.Views.View.TouchEventArgs e2) =>
{
if (e2.Event.Action == MotionEventActions.Down)
{
.
.
.
}
else if (e2.Event.Action == MotionEventActions.Up)
{
.
.
.
}
else if (e2.Event.Action == MotionEventActions.HoverExit || e2.Event.Action == MotionEventActions.Cancel)
{
.
.
.
}
else if (e2.Event.Action == MotionEventActions.Move)
{
.
. …Run Code Online (Sandbox Code Playgroud) 我已经尝试了很多关于如何解决这个问题的解决方案。我的调试工作正常。但截至目前,我正在尝试在发布模式下构建我的 apk 存档。当我在发布模式下重新构建时,出现错误Java exited with code 1 (MSB6006)。
在我的 Droid 项目中启用了 Proguard 和 multi-dex。我的堆大小也已经设置为 1G。我还在我的 Droid 项目中创建了一个 proguard.cfg 文件,但我仍然遇到同样的错误。当我检查错误参考时,它会在我的浏览器中引导我MSBuild.ToolTask.ToolCommandFailed。
还有其他我可以解决这个问题吗?
附件是https://gist.github.com/anonymous/9e7fba8cc745ce9ae06fa2c8ae075697 - 完整的诊断构建输出。
配置文件
# This is Xamarin-specific (and enhanced) configuration.
-dontobfuscate
-keep class mono.MonoRuntimeProvider { *; <init>(...); }
-keep class mono.MonoPackageManager { *; <init>(...); }
-keep class mono.MonoPackageManager_Resources { *; <init>(...); }
-keep class mono.android.** { *; <init>(...); }
-keep class mono.java.** { *; <init>(...); }
-keep class mono.javax.** { *; <init>(...); }
-keep …Run Code Online (Sandbox Code Playgroud) 如果我有更多的选项卡而不适合屏幕,在 Android 上我可以将选项卡模式设置为可滚动。但是,如果我以编程方式将所选项目(使用 SelectedItem 或 CurrentPage)设置为屏幕外的选项卡,在 Android 上,选项卡不会滚动。
在 UWP 上它工作正常,在 iOS 上它不起作用,因为它使用“更多”按钮。但在 Android 上,它会选择正确的 Child,显示其内容,但不会将选项卡滚动到正确的选项卡(如果它不在屏幕上)。
如果我手动滚动选项卡,则会选择正确的选项卡,但这种用户体验非常糟糕。
显然是 Xamarin Forms 的一个错误,但我不希望很快有任何变化,所以关于如何以编程方式滚动选项卡的任何想法?
这是带有示例应用程序的错误报告以查看问题。
我rg.plugins.popup在我的应用程序中使用过。我已经更新了 xamarin 表单(version="2.5.0.121934")。现在单击外部背景并没有关闭。我曾经通过多种方式关闭弹出窗口,但没有关闭,我尝试了以下代码:
this.CloseWhenBackgroundIsClicked = false;
protected override bool OnBackgroundClicked()
{
Navigation.PopPopupAsync();
return false;
}
Run Code Online (Sandbox Code Playgroud)
OnBackgroundClicked不是在打电话。如何解决这个问题?
我安装了Visual Studio 2017.在安装程序菜单中,我安装了Xamarin和Visual C#.但是,当我创建一个新项目时,转到工具>选项> Xamarin,我看到android-ndk文本框是空的而其他文件框不是.
我在这条路径上安装了Visual Studio:D:\ Program Files\Visual Studio.但我不知道是否会将Xamarin安装到D:\
我的问题是android-ndk在哪里?
谢谢
android android-ndk xamarin.android xamarin visual-studio-2017
我已经loop在我的代码中添加Views了Layout,下面的代码是一个Loop which is present in another loop,我有这么多的循环,Activity takes so much time to start如何处理这个?
foreach (InfoQuery item in InfoList)
{
if (item == "kitten")
{
if (!done)
{
TextView view= new TextView(ApplicationContext);
view.LayoutParameters = mainLayout.LayoutParameters;
view.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 3, ApplicationContext.Resources.DisplayMetrics);
view.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, ApplicationContext.Resources.DisplayMetrics), 0, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, ApplicationContext.Resources.DisplayMetrics), 0);
view.Text = item.position;
layout2.AddView(view,0);
done = true;
}
TextView view2= new TextView(ApplicationContext);
view2.LayoutParameters = mainLayout.LayoutParameters;
view2.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 3, ApplicationContext.Resources.DisplayMetrics); ;
view2.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 30, …Run Code Online (Sandbox Code Playgroud) android xamarin.android android-inflate android-view xamarin
xamarin.android ×10
xamarin ×7
android ×5
c# ×2
xamarin.ios ×2
android-ndk ×1
android-view ×1
apk ×1
java ×1
webview ×1