我正在使用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「」。 –