나는 홈 화면 위젯의 차트를 그릴 AndroidPlot를 사용하는 것을 시도하고있다. 나는 일반 응용 프로그램에서, 그것은 사용자 지정보기를 사용하는 것을 알고 내가 본 것과 (Android: AppWidget with custom view not working), 해결 방법은 imageView
에서 비트 맵으로이 렌더링하는 것입니다. AndroidPlot : AppWidget에서 차트를 렌더링하는 방법?
이 코드와 원래의 빠른 시작 코드의 차이점은 빠른 시작의 경우 Activity.findViewById
을 활용하지만 분명히 여기서는 사용할 수 없다는 것입니다.
는 아무도 내가 빈 렌더링의 원인이 될 수 잘못하고 있어요 것을 여기서 뭔가를 볼 수 있을까요? 제공 할 수있는 도움을 주시면 감사하겠습니다.
private Bitmap getChartImage(Context context)
{
// initialize our XYPlot reference:
mySimpleXYPlot = new XYPlot(context, "My Simple XYPlot");
mySimpleXYPlot.setDrawingCacheEnabled(true);
// add a new series
mySimpleXYPlot.addSeries(new SimpleXYSeries(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0)));
// reduce the number of range labels
mySimpleXYPlot.getGraphWidget().setRangeTicksPerLabel(4);
// reposition the domain label to look a little cleaner:
Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget();
mySimpleXYPlot.position(domainLabelWidget, // the widget to position
45, // x position value, in this case 45 pixels
XLayoutStyle.ABSOLUTE_FROM_LEFT, // how the x position value is applied, in this case from the left
0, // y position value
YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
AnchorPosition.LEFT_BOTTOM); // point to use as the origin of the widget being positioned
// get rid of the visual aids for positioning:
mySimpleXYPlot.disableAllMarkup();
//mySimpleXYPlot.measure(150, 150);
//mySimpleXYPlot.layout(0, 0, 150, 150);
Bitmap bmp = mySimpleXYPlot.getDrawingCache();
return bmp;
}
그는 어떻게 레이아웃을 사용하기 전에 차트의 크기를 계산 했습니까? 150은 하드 코드 된 것입니다 ... –