Android Align Image Buttons On A Curve?
I have a series of buttons on a main menu. Instead of the standard side by side, or one on top of the other, I'd like them to be aligned around a semi-circle. Since I can't drag an
Solution 1:
Here's an example which plots a series of TextViews around a circle. You should be able to adapt it to suit your needs.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
AbsoluteLayout al = new AbsoluteLayout(this);
setContentView(al);
double radius = 75;
double cx = 100, cy = 100;
for(double angle = 0; angle < 360; angle += 30) {
double radAngle = Math.toRadians(angle);
double x = (Math.cos(radAngle)) * radius + cx;
double y = (1 - Math.sin(radAngle)) * radius + cy;
TextView textView = new TextView(this);
textView.setText(Double.toString(angle));
AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(60, 30, (int) x, (int) y);
textView.setLayoutParams(lp);
al.addView(textView);
}
}
Post a Comment for "Android Align Image Buttons On A Curve?"