为了账号安全,请及时绑定邮箱和手机立即绑定

老师 我想问 如果主按钮 在中间 item呈180°散开 怎么做

老师 我想问 如果主按钮 在中间  item呈180°散开 怎么做

正在回答

1 回答

散开路径:

int l1 = (int) (mRadius * Math.sin(Math.PI / count * (i + 1)));
int t1= (int) (mRadius * Math.cos(Math.PI / count * (i + 1)));

int xflag = 1;
int yflag = 1;
AnimationSet animset = new AnimationSet(true);
Animation tranAnim = null;
if (mCurrentStatus == Status.CLOSE)
{
    tranAnim = new TranslateAnimation(xflag * t1, 0, yflag * l1, 0);
    childView.setClickable(true);
    childView.setFocusable(true);
}
else
{
    tranAnim = new TranslateAnimation(0, xflag * t1, 0, yflag * l1);
    childView.setClickable(false);
    childView.setFocusable(false);
}

主菜单和子菜单定位:

protected void onLayout(boolean changed, int l, int t, int r, int b) {
    if (changed){
        layoutCButton();
        int count = getChildCount();
        for (int i=0;i<count-1;i++){
            View child = getChildAt(i+1);
            child.setVisibility(View.GONE);
            int t1 = (int) (mRadius * Math.sin(Math.PI / count * (i + 1)));
            int l1= (int) (mRadius * Math.cos(Math.PI / count * (i + 1)));

            int width = child.getMeasuredWidth();
            int height = child.getMeasuredHeight();
            l = getMeasuredWidth() / 2 - width / 2 - l1;
            t = getMeasuredHeight() - height - t1;

            child.layout(l, t, l + width, t + height);
        }

    }

}

private void layoutCButton() {
    mCButton = getChildAt(0);
    mCButton.setOnClickListener(this);

    int l = 0;
    int t = 0;

    int width = mCButton.getMeasuredWidth();
    int height = mCButton.getMeasuredHeight();
    switch (mPosition){
        case CENTER:
            l = getMeasuredWidth() / 2 - width / 2;
            t = getMeasuredHeight() - height;
            break;
    }
    mCButton.layout(l, t, l + width, t + height);
}


1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android实现卫星菜单
  • 参与学习       26334    人
  • 解答问题       55    个

学习仿Path的卫星式菜单,课程涵盖了自定义控件的整个过程

进入课程

老师 我想问 如果主按钮 在中间 item呈180°散开 怎么做

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信