我正在使用xamarin在visual studio 2015中使用android。我想添加一个图表,因此对于基本了解,我跟进了oxyplot
并下载了文档(示例代码)。现在我只是复制源代码,但通过编写代码。当我到达FindViewById<PlotView>(Resource.Id)
点时,我无法在其中找到Id
字段。为了更好的理解,请参阅波纹图像和代码Xamarin android无法找到id字段
贝娄是从我正在复制
using Android.App;
using Android.OS;
using OxyPlot.Xamarin.Android;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
namespace AndroidApp1
{
[Activity(Label = "AndroidApp1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
PlotView view = FindViewById<PlotView>(Resource.Id.plot_view);
view.Model = CreatePlotModel();
}
private PlotModel CreatePlotModel()
{
var plotModel = new PlotModel { Title = "OxyPlot Demo" };
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Maximum = 10, Minimum = 0 });
var series1 = new LineSeries
{
MarkerType = MarkerType.Circle,
MarkerSize = 4,
MarkerStroke = OxyColors.White
};
series1.Points.Add(new DataPoint(0.0, 6.0));
series1.Points.Add(new DataPoint(1.4, 2.1));
series1.Points.Add(new DataPoint(2.0, 4.2));
series1.Points.Add(new DataPoint(3.3, 2.3));
series1.Points.Add(new DataPoint(4.7, 7.4));
series1.Points.Add(new DataPoint(6.0, 6.2));
series1.Points.Add(new DataPoint(8.9, 8.9));
plotModel.Series.Add(series1);
return plotModel;
}
}}
贝娄的代码是在我写
using Android.App;
using Android.OS;
using OxyPlot.Xamarin.Android;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
namespace SampleChart
{
[Activity(Label = "SampleChart", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
PlotView view = FindViewById<PlotView>(Resource.Id)
}
}}
我不知道我错过了什么。 任何帮助,将不胜感激
你能提供您Main.axml布局,使我们能够确保你有视图和id设置是否正确?你应该在你的视图中有“android:id =”@ + id/plot_view“”。 –