課程
/移動(dòng)開發(fā)
/Android
/Android實(shí)現(xiàn)衛(wèi)星菜單
老師 我想問(wèn) 如果主按鈕 在中間 ?item呈180°散開 怎么做
2017-01-02
源自:Android實(shí)現(xiàn)衛(wèi)星菜單 1-4
正在回答
散開路徑:
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); }
舉報(bào)
學(xué)習(xí)仿Path的衛(wèi)星式菜單,課程涵蓋了自定義控件的整個(gè)過(guò)程
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-01-13
散開路徑:
主菜單和子菜單定位: