Android的一个曲线调整图像按钮? [英] Android align Image Buttons on a curve?

查看:155
本文介绍了Android的一个曲线调整图像按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主菜单上的一系列按钮。代替由侧的标准侧,或在另一个的顶部的一个的,我希望他们周围半圆形对齐。既然不能拖放按钮的地方,我想在设计师,我想知道这样做的最佳方式?我能做到这一点的XML,否则将是最好的编程呢?

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?

推荐答案

下面是它绘制了一系列一圈TextViews的例子。您应该能够适应它以满足您的需求。

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);
    }
}

这篇关于Android的一个曲线调整图像按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆