我正在Visual Studio 2015中使用xamarin在android上工作。我想添加一个图表,因此为了基本了解,我跟进了oxyplot
并下载了文档(示例代码)。现在我只是复制源代码,而是通过编写代码。当我到达FindViewById<PlotView>(Resource.Id)
点时,在其中找不到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)
}
}}
我不知道我在想什么。
任何帮助,将不胜感激
最佳答案
您要访问的ID必须在Xml文件中定义
像这样的东西
android:id =“ @ + id / Content”
这样您就可以指出具有ID的资源,或者必须在另一个文件中优化它,例如values-> id.xml