自定义左下角弧形旋转菜单栏

自定义左下角弧形旋转菜单栏_第1张图片

要做这种效果

1- 整个自定义控件其实就是一个ArcMenu .(半圆形那一圈),左下角的图标没有加入进控件中。 
写这个自定义menu.之前有参考 
daCapricorn/ArcMenu

2- 我基于他的类改了点。

  • 他是将左下角的关闭icon都加入到整个自定义menu的layout中的,我是独立出来

  • 我menu中的item添加的思路是首先都给它固定在界面的最左边,往屏幕左边外面便宜半个item的宽度。然后在draw时,将每一个item的位置根据自身的角度,设置rotate值,不但外面要rotate到item本身应该所在的位置(pivot要设置为左下角为原点),它自身也得根据偏移的角度rotate到一个正确的向上的角度。其实在初始化时都给它们偏移过了。

3- 当然现在6.0、7.0上的那些自带效果比我这漂亮多了,不过为了完成设计师给的设计稿,不得不这样写。所以轻喷。

4- 下面po上实现步骤。

a,自定义一个类ArcMenu继承自FrameLayout.重载三个构造方法。

public class ArcMenu extends FrameLayout {
public ArcMenu(Context context) {super(context);}
public ArcMenu(Context context, AttributeSet attrs) {super(context, attrs);}
<span style="font-family: 'microsoft yahei'; background-color: rgb(246, 246, 246);">
</span>
<span style="font-family: 'microsoft yahei'; background-color: rgb(246, 246, 246);">b,重写 onSizeChanged方法,确定控件的高宽,并初始化控件中的一些参数</span>
<span style="font-family: 'microsoft yahei'; background-color: rgb(246, 246, 246);"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhgAAABdCAYAAADnjh/mAAAYl0lEQVR4Ae2df0xcVZvHv5d1101WWhSSfVsonQGqtqVGfem7BZtaC11sXn1beFPFH3mRWkz5p0QwaYPERoNNTdoamk0wlhQxr4baWNrqG+0WtDYKuvD+2ErtazvMjAWqmwVFcP/Y7K53c86dO7+4c+dH7zDMzJeEzL3nnOc5z/mcc2ee+5xz71EGp4ZV8I8ESIAESIAESIAELCSQYaEuqiIBEiABEiABEiABSYAOBgcCCZAACZAACZCA5QToYFiOlApJgARIgARIgAToYHAMkAAJkAAJkAAJWE6ADoblSKmQBEiABEiABEiADgbHAAm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IAESIIHEELDEwdA2GCvR3h3ht/FYYprEWkmABEiABEiABBJNwBIHQ+wkWnN2GAOTvWhEHz51JbpZrJ8ESIAESIAESCCRBCxxMPQGCEcjf7V+xk8SIAESIAESIIF0JWCpgyGmSq5dKkK+PV1xst0kQAIkQAIkQAKCgKUOhhbBcOAap0g4ukiABEiABEggrQlY6mAIkqWHXgIa1qKUiz3TemCx8SRAAiRAAulN4Carmz/YXAX3c0MY3MzXYlvNlvpIgARIgARIIFkIWBrB0NZgVGFDRbI0n3aSAAmQAAmQAAnEg4ClDgbXYMSji6iTBEiABEiABJKPgKUOhhbBSD4ItJgESIAESIAESMBaApY4GPqbPMtyqtCOCqznY6rW9hK1kQAJkAAJkECSEbB0u/YkazvNJQESIAESIAESiBMBSyIYcbKNakmABEiABEiABJKUAB2MJO04mk0CJEACJEACC5nA/wMIKgmZZwBjdgAAAABJRU5ErkJggg==" alt="" />
</span>
<span style="font-family: 'microsoft yahei'; background-color: rgb(246, 246, 246);">
</span>
<span style="font-family: 'microsoft yahei'; background-color: rgb(246, 246, 246);"></span><pre style="font-family: 'Source Code Pro'; background-color: rgb(199, 237, 204);"><span style="font-size:14px;"><span style="color: rgb(0, 0, 128); "><strong>private void </strong></span>init() {

      <span style="color: rgb(0, 0, 128); "><strong>if </strong></span>(!isInEditMode()) {
         <span style="color: rgb(0, 0, 128); "><strong>for </strong></span>(<span style="color: rgb(0, 0, 128); "><strong>int </strong></span>i = <span style="color: rgb(0, 0, 255);">0</span><span style="color: rgb(24, 14, 6);">; </span>i < <span style="color: rgb(102, 14, 122);  "><strong><em>ICON_COUNT</em></strong></span><span style="color: rgb(24, 14, 6);">; </span>i++) {</span>
    //初始化默认和点击的图片bitmap
            m_iconGrayBitmaps[i] = DrawableManager.instance().getAssetBitmap(s_iconNamePrefixes[i] + "_gray.png");  m_iconWhiteBitmaps[i] = DrawableManager.instance().getAssetBitmap(s_iconNamePrefixes[i] + "_white.png"); // m_tangent[i] = Math.tan(90.0f / ICON_COUNT * i);  }
      }
      m_arcWidth = m_height / 4;//弧形的宽度 // m_itemIndex = 0;  m_startDegree = 90.0f / ICON_COUNT / 2; //第一个item初始化时应该待的位置的偏移角度  m_stepDegree = 90.0f / ICON_COUNT; //每一个item相对前一个item所偏移的角度  
 //新建一个矩形,中心点为左下角
  m_arcRect = new RectF(-(m_width - m_arcWidth / 2), m_arcWidth / 2,  m_width - m_arcWidth / 2, 2 * m_height - m_arcWidth / 2);   int shadow_arc_width = Utils.dp2px(SHADOW_ARC_WIDTH);  m_arcShadow = new RectF(-(m_width - m_arcWidth - shadow_arc_width / 2), m_arcWidth + shadow_arc_width / 2,  (m_width - m_arcWidth - shadow_arc_width / 2), 2 * m_height - m_arcWidth - shadow_arc_width / 2);   m_arcbgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  m_arcbgPaint.setStyle(Paint.Style.STROKE);  m_arcbgPaint.setStrokeWidth(m_arcWidth);  m_arcbgPaint.setColor(getResources().getColor(R.color.bg_menu_arc));  m_arcfgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  m_arcfgPaint.setStyle(Paint.Style.STROKE);  m_arcfgPaint.setStrokeWidth(m_arcWidth);  m_arcfgPaint.setColor(getResources().getColor(R.color.fg_menu_arc));  m_shadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  m_shadowPaint.setStyle(Paint.Style.STROKE);  m_shadowPaint.setStrokeWidth(shadow_arc_width);  m_shadowPaint.setColor(getResources().getColor(R.color.default_black));   setOnTouchListener(new OnTouchListener() {
         @Override  public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
               int index = pointInArc(event.getX(), event.getY());  if (index >= 0) {
                  Logger.debug("click on icon " + index);  m_itemIndex = index;  invalidate();  m_itemClickedListener.onMenuItemClicked(index);  return true;  }
            }
            return false;  }
      });  }
 
  
上面图画错了。。绿色框其实就是外面的m_arcRect
shadowArc其实是 那一层黑色的arc..我懒得再画了。。
</pre><pre name="code" class="java">接下来就是画图了。把那些item要画上去,还得画上这两层弧形
用到dipatchDraw
<pre style="font-family: 'Source Code Pro'; font-size: 9pt; background-color: rgb(199, 237, 204);"><span style="color:#808000;">@Override
</span><span style="color:#000080;"><strong>protected void </strong></span>dispatchDraw(Canvas canvas) {
   Path path = <span style="color:#000080;"><strong>new </strong></span>Path()<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span><span style="color:#808080;"><em>/// draw out arc
</em></span><span style="color:#808080;"><em>   </em></span>path.arcTo(<span style="color:#660e7a;"><strong>m_arcRect</strong></span><span style="color:#180e06;">, </span><span style="color:#0000ff;">270.0f</span><span style="color:#180e06;">, </span><span style="color:#0000ff;">90.0f</span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span>canvas.drawPath(path<span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_arcbgPaint</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">
</span><span style="color:#180e06;">   </span>canvas.drawArc(<span style="color:#660e7a;"><strong>m_arcRect</strong></span><span style="color:#180e06;">, </span><span style="color:#0000ff;">270.0f </span>+ <span style="color:#660e7a;"><strong>m_stepDegree </strong></span>* <span style="color:#660e7a;"><strong>m_itemIndex</strong></span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_stepDegree</strong></span><span style="color:#180e06;">, </span><span style="color:#000080;"><strong>false</strong></span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_arcfgPaint</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span><span style="color:#808080;"><em>/// draw shadow arc
</em></span><span style="color:#808080;"><em>   </em></span>canvas.drawArc(<span style="color:#660e7a;"><strong>m_arcShadow</strong></span><span style="color:#180e06;">, </span><span style="color:#0000ff;">270.0f</span><span style="color:#180e06;">, </span><span style="color:#0000ff;">90.0f</span><span style="color:#180e06;">, </span><span style="color:#000080;"><strong>false</strong></span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_shadowPaint</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">
</span><span style="color:#180e06;">   </span><span style="color:#808080;"><em>/// draw bitmaps
</em></span><span style="color:#808080;"><em>   </em></span><span style="color:#000080;"><strong>for </strong></span>(<span style="color:#000080;"><strong>int </strong></span>i = <span style="color:#0000ff;">0</span><span style="color:#180e06;">; </span>i < <span style="color:#660e7a;"><strong><em>ICON_COUNT</em></strong></span><span style="color:#180e06;">; </span>i++) {
      Bitmap bitmap<span style="color:#180e06;">;
</span><span style="color:#180e06;">      </span><span style="color:#000080;"><strong>if </strong></span>(i == <span style="color:#660e7a;"><strong>m_itemIndex</strong></span>) { <span style="color:#808080;"><em>/// selected icon
</em></span><span style="color:#808080;"><em>         </em></span>bitmap = <span style="color:#660e7a;"><strong>m_iconWhiteBitmaps</strong></span>[i]<span style="color:#180e06;">;
</span><span style="color:#180e06;">      </span>} <span style="color:#000080;"><strong>else </strong></span>{    <span style="color:#808080;"><em>/// not selected
</em></span><span style="color:#808080;"><em>         </em></span>bitmap = <span style="color:#660e7a;"><strong>m_iconGrayBitmaps</strong></span>[i]<span style="color:#180e06;">;
</span><span style="color:#180e06;">      </span>}
      <span style="color:#000080;"><strong>if </strong></span>(bitmap != <span style="color:#000080;"><strong>null</strong></span>) {
         Matrix matrix = <span style="color:#000080;"><strong>new </strong></span>Matrix()<span style="color:#180e06;">;
</span><span style="color:#180e06;">         </span>matrix.postTranslate(-bitmap.getWidth() / <span style="color:#0000ff;">2</span><span style="color:#180e06;">, </span>(<span style="color:#660e7a;"><strong>m_arcWidth </strong></span>- bitmap.getHeight()) / <span style="color:#0000ff;">2</span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">         </span>matrix.postRotate(-<span style="color:#660e7a;"><strong>m_startDegree </strong></span>- <span style="color:#660e7a;"><strong>m_stepDegree </strong></span>* i<span style="color:#180e06;">, </span><span style="color:#0000ff;">0</span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_arcWidth </strong></span>/ <span style="color:#0000ff;">2</span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">         </span>matrix.postRotate(<span style="color:#660e7a;"><strong>m_startDegree </strong></span>+ <span style="color:#660e7a;"><strong>m_stepDegree </strong></span>* i<span style="color:#180e06;">, </span><span style="color:#0000ff;">0</span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_height</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">         </span>canvas.drawBitmap(bitmap<span style="color:#180e06;">, </span>matrix<span style="color:#180e06;">, </span><span style="color:#000080;"><strong>null</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">      </span>}
   }

   <span style="color:#000080;"><strong>super</strong></span>.dispatchDraw(canvas)<span style="color:#180e06;">;
</span>}

 
  
写到这里不知道怎么说了。。干脆贴代码算了。
<pre style="font-family: 'Source Code Pro'; font-size: 9pt; background-color: rgb(199, 237, 204);"><span style="color:#808080;"><em>/**
</em></span><span style="color:#808080;"><em> * check if point (x, y) is within arc icon
</em></span><span style="color:#808080;"><em> *
</em></span><span style="color:#808080;"><em> * </em></span><span style="color:#808080;"><strong><em>@param </em></strong></span><span style="color:#3d3d3d;"><strong><em>x
</em></strong></span><span style="color:#3d3d3d;"><strong><em> </em></strong></span><span style="color:#808080;"><em>* </em></span><span style="color:#808080;"><strong><em>@param </em></strong></span><span style="color:#3d3d3d;"><strong><em>y
</em></strong></span><span style="color:#3d3d3d;"><strong><em> </em></strong></span><span style="color:#808080;"><em>* </em></span><span style="color:#808080;"><strong><em>@return </em></strong></span><span style="color:#808080;"><em>index of the icon clicked, or -1
</em></span><span style="color:#808080;"><em> */
</em></span><span style="color:#000080;"><strong>private int </strong></span>pointInArc(<span style="color:#000080;"><strong>float </strong></span>x<span style="color:#180e06;">, </span><span style="color:#000080;"><strong>float </strong></span>y) {
   <span style="color:#000080;"><strong>float</strong></span>[] pts = {x<span style="color:#180e06;">, </span>y}<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span><span style="color:#000080;"><strong>float</strong></span>[] target_pts = <span style="color:#000080;"><strong>new float</strong></span>[<span style="color:#0000ff;">2</span>]<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span>Matrix matrix = <span style="color:#000080;"><strong>new </strong></span>Matrix()<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span>matrix.postRotate(-<span style="color:#660e7a;"><strong>m_startDegree</strong></span><span style="color:#180e06;">, </span><span style="color:#0000ff;">0</span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_height</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span><span style="color:#000080;"><strong>for </strong></span>(<span style="color:#000080;"><strong>int </strong></span>i = <span style="color:#0000ff;">0</span><span style="color:#180e06;">; </span>i < <span style="color:#660e7a;"><strong><em>ICON_COUNT</em></strong></span><span style="color:#180e06;">; </span>i++) {
      matrix.mapPoints(target_pts<span style="color:#180e06;">, </span>pts)<span style="color:#180e06;">;
</span><span style="color:#180e06;">      </span><span style="color:#000080;"><strong>if </strong></span>(pointInStartRectOfIcon(target_pts)) {
         <span style="color:#000080;"><strong>return </strong></span>i<span style="color:#180e06;">;
</span><span style="color:#180e06;">      </span>}
      matrix.postRotate(-<span style="color:#660e7a;"><strong>m_stepDegree</strong></span><span style="color:#180e06;">, </span><span style="color:#0000ff;">0</span><span style="color:#180e06;">, </span><span style="color:#660e7a;"><strong>m_height</strong></span>)<span style="color:#180e06;">;
</span><span style="color:#180e06;">   </span>}

   <span style="color:#000080;"><strong>return </strong></span>-<span style="color:#0000ff;">1</span><span style="color:#180e06;">;
</span>}

<span style="color:#808080;"><em>/**
</em></span><span style="color:#808080;"><em> * check if (target_pts[0], target_pts[1]) is in the start position of icons
</em></span><span style="color:#808080;"><em> *
</em></span><span style="color:#808080;"><em> * </em></span><span style="color:#808080;"><strong><em>@param </em></strong></span><span style="color:#3d3d3d;"><strong><em>target_pts
</em></strong></span><span style="color:#3d3d3d;"><strong><em> </em></strong></span><span style="color:#808080;"><em>* </em></span><span style="color:#808080;"><strong><em>@return
</em></strong></span><span style="color:#808080;"><strong><em> </em></strong></span><span style="color:#808080;"><em>*/
</em></span><span style="color:#000080;"><strong>private boolean </strong></span>pointInStartRectOfIcon(<span style="color:#000080;"><strong>float</strong></span>[] target_pts) {
   <span style="color:#000080;"><strong>return </strong></span>target_pts[<span style="color:#0000ff;">0</span>] > -<span style="color:#660e7a;"><strong>m_arcWidth </strong></span>/ <span style="color:#0000ff;">2 </span>&& target_pts[<span style="color:#0000ff;">0</span>] < <span style="color:#660e7a;"><strong>m_arcWidth </strong></span>/ <span style="color:#0000ff;">2
</span><span style="color:#0000ff;">          </span>&& target_pts[<span style="color:#0000ff;">1</span>] > <span style="color:#0000ff;">0 </span>&& target_pts[<span style="color:#0000ff;">1</span>] < <span style="color:#660e7a;"><strong>m_arcWidth</strong></span><span style="color:#180e06;">;
</span>}
/**  * Sets the click listener for menu items.  */ public void setOnItemClickedListener(ArcMenuItemClickedListener itemClickedListener) {
   this.m_itemClickedListener = itemClickedListener;
}

public void setSelectedIcon(int index, boolean bInvalidate) {
   m_itemIndex = index;
   if(bInvalidate) {
      invalidate();
   }
}
就酱吧。。。写个博客烦球死。。
 
  
</pre><pre name="code" class="java">..

你可能感兴趣的:(控件)