Reputation: 449
I am using AchartEngine Lib for displaying Pie chart inside my application, but I am facing a weird issue like when I changes the orientation of my phone the pie chart is not centred aligned it changes the direction anywhere. Please let me know how can I centre aligne the pie Chart?
Upvotes: 0
Views: 584
Reputation: 2113
I had the same problem creating it inside a Fragment.
After spending hours and hours, I managed to do it by overriding onConfigurationChanged method.
The problem is that onConfigurationChanged is called before the layout change, and I couldn't find any method called after layout. Adding a sleep into it seems to do the trick.
You must remove the chartView from your layout, make it null, recreate it and then add again to the layout.
Code:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch(Exception e) { }
chartLayout.removeView(mChartView);
mChartView = null;
mChartView = ChartFactory.getPieChartView(getActivity(), mSeries, mRenderer);
chartLayout.addView(mChartView);
}
});
}
Upvotes: 5