views:

35

answers:

1

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 and drop the buttons to the place I'd like to in the designer, I was wondering the best way to do this? Can I do it in the XML, or would it be best to do it programatically?

+1  A: 

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);
    }
}
Andy
What I'm getting is that there really isn't a way to do it in the XML or with the GUI designer, right? Its just as well; the GUI designer is pretty terrible. Your code, however, does do pretty much what I wanted to do. Thanks!
s73v3r
Actually, since AbsoluteLayout is deprecated, what should be used instead?
s73v3r
AbsoluteLayout is deprecated because there are so many different screen sizes now. You can still use it, but you have the responsibility to override "onSizeChanged()" and reposition the child views according to the new size.
Andy