最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義控件實現(xiàn)UC瀏覽器語音搜索效果

 更新時間:2017年04月22日 14:26:33   作者:ludi  
這篇文章主要為大家詳細介紹了Android自定義控件實現(xiàn)UC瀏覽器語音搜索效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

 最近項目上要實現(xiàn)語音搜索功能,界面樣式要模仿一下UC瀏覽器的樣式,UC瀏覽器中有一個控件,會隨著聲音大小浮動,然后尋思偷個懶,百度一下,結(jié)果也沒有找到類似的,只能自己動手了。

先上圖看我實現(xiàn)的效果:

這是自定義控件的代碼,里面注釋也很明白,就不費話了

public class CustomCircleView extends View{
  private Paint mPaint;
  private int strokeWidth = 0;   //圓環(huán)的寬度
  private Bitmap bitmap = null;  // 圖片位圖
  private int nBitmapWidth = 0;  // 圖片的寬度
  private int nBitmapHeight = 0; // 圖片的高度
  private int width;     //view的寬度
  private int height ;    //view的高度
  private int bigCircleColor =0;    //view的高度
  private int floatCircleColor =0;    //view的高度

  public CustomCircleView(Context context) {
    this(context, null);
  }

  public CustomCircleView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public CustomCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomCircleView, defStyleAttr, 0);
    int n = a.getIndexCount();

    for (int i = 0; i < n; i++)
    {
      int attr = a.getIndex(i);
      switch (attr)
      {
        case R.styleable.CustomCircleView_icon:
          bitmap = BitmapFactory.decodeResource(getResources(), a.getResourceId(attr, 0));
          break;
        case R.styleable.CustomCircleView_bigCircleColor:
          bigCircleColor = a.getColor(attr, Color.GRAY);
          break;
        case R.styleable.CustomCircleView_floatCircleColor:
          floatCircleColor = a.getColor(attr,Color.GREEN);
          break;
      }
    }
    a.recycle();

    mPaint = new Paint();
    //如果布局中沒有設(shè)置bigCircleColor和floatCircleColor的時候給他一個默認值
    if (bigCircleColor==0){
      bigCircleColor=Color.parseColor("#FFEEF0F1");
    }
    if (floatCircleColor==0){
      floatCircleColor=Color.parseColor("#25c1f5");
    }
    // 獲取圖片高度和寬度
    nBitmapWidth = bitmap.getWidth();
    nBitmapHeight = bitmap.getHeight();
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    //獲取view的高度和寬度 這個view必須給精確值?。。。。。。。?
    if (widthMode == MeasureSpec.EXACTLY) {
      width = widthSize;
    }
    if (heightMode == MeasureSpec.EXACTLY)
    {
      height = heightSize;
    }
    setMeasuredDimension(width, height);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mPaint.setAntiAlias(true); // 消除鋸齒
    //繪制最外層灰色大圓
    mPaint.setColor(bigCircleColor);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(height/2-nBitmapHeight/2);
    //計算圓的半徑稍微麻煩點,但是在圖上畫一下應(yīng)該能明白 (height/2-nBitmapHeight/2)/2+nBitmapHeight/2
    canvas.drawCircle(width/2, height/2, (height/2-nBitmapHeight/2)/2+nBitmapHeight/2, mPaint);

    //繪制浮動的圓
    mPaint.setColor(floatCircleColor);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(strokeWidth);
    canvas.drawCircle(width/2, height/2, strokeWidth/2+nBitmapHeight/2, mPaint);

    //繪制中間圖標(biāo)
    canvas.drawBitmap(bitmap, width/2-nBitmapWidth/2, height/2-nBitmapHeight/2, mPaint);


  }
  //根據(jù)傳入的寬度重新繪制
  public void setStrokeWidth(int with){
    this.strokeWidth=with;
    invalidate();
  }
}

在res/values 下建一個attrs文件 代碼:

<resources>
  <declare-styleable name="CustomCircleView">
    <attr name="bigCircleColor" format="color" />
    <attr name="floatCircleColor" format="color" />
    <attr name="icon" format="reference" />
  </declare-styleable>
</resources>

在布局中的使用:

<com.example.administrator.mycustomcircleview.CustomCircleView
  android:id="@+id/customView"
  android:layout_width="200dp"
  android:layout_height="200dp"
  android:layout_gravity="center"
  app:icon="@mipmap/voice_icon"
  app:floatCircleColor="@color/colorAccent"
  app:bigCircleColor="@color/colorPrimaryDark"
  />


高度寬度一定要給精確值,切記啊?。?!顏色值可以不設(shè)定,默認就是我上面圖的效果。
然后根據(jù)音量大小直接傳入數(shù)值就可以了,很簡單的使用方法,這里我用隨機數(shù)代替了。

customView = ((CustomCircleView) findViewById(R.id.customView));
  button = ((Button) findViewById(R.id.button));
  button.setOnClickListener(this);
}

@Override
public void onClick(View v) {
  Random random=new Random();
  customView.setStrokeWidth(random.nextInt(100));
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實現(xiàn)微信聊天語言點擊喇叭動畫效果

    Android實現(xiàn)微信聊天語言點擊喇叭動畫效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)微信聊天語言點擊喇叭動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android 判斷是否能真正上網(wǎng)的實例詳解

    Android 判斷是否能真正上網(wǎng)的實例詳解

    這篇文章主要介紹了Android 判斷是否能真正上網(wǎng)的實例詳解相關(guān)資料,希望通過本文大家能夠掌握判斷是否上網(wǎng)的方法,需要的朋友可以參考下
    2017-10-10
  • Android仿QQ可拉伸頭部控件

    Android仿QQ可拉伸頭部控件

    這篇文章主要為大家詳細介紹了Android仿QQ可拉伸頭部控件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android?Notes思碼逸問題處理記錄

    Android?Notes思碼逸問題處理記錄

    這篇文章主要介紹了Android?Notes思碼逸問題處理記錄詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Android實現(xiàn)仿excel數(shù)據(jù)表格效果

    Android實現(xiàn)仿excel數(shù)據(jù)表格效果

    這篇文章主要介紹了Android實現(xiàn)仿excel數(shù)據(jù)表格效果的實現(xiàn)代碼,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-10-10
  • Android日期選擇控件使用詳解

    Android日期選擇控件使用詳解

    這篇文章主要為大家詳細介紹了Android日期選擇控件的使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Android TouchListener實現(xiàn)拖拽刪實例代碼

    Android TouchListener實現(xiàn)拖拽刪實例代碼

    這篇文章主要介紹了Android TouchListener實現(xiàn)拖拽刪實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Android端部署DeepSeek的詳細教程

    Android端部署DeepSeek的詳細教程

    DeepSeek最近幾個月很火熱,很多產(chǎn)品以及企業(yè)都在接入DeepSeek,比如微信搜索接入,可以搜索公眾號信息并總結(jié),這個對于查一些資料還挺好用,畢竟手機才是用戶用的最多的,既然談到了手機,那么DeepSeek能否部署于手機之上呢,本文給大家介紹了android端部署的DeepSeek方法
    2025-03-03
  • 詳解Android Handler機制和Looper Handler Message關(guān)系

    詳解Android Handler機制和Looper Handler Message關(guān)系

    Handler是Android線程之間的消息機制,主要的作用是將一個任務(wù)切換到指定的線程中去執(zhí)行,準(zhǔn)確的說是切換到構(gòu)成Handler的looper所在的線程中去出處理。本文將詳細介紹Android Handler機制和Looper Handler Message關(guān)系。
    2021-06-06
  • Android自定義view之利用drawArc方法實現(xiàn)動態(tài)效果(思路詳解)

    Android自定義view之利用drawArc方法實現(xiàn)動態(tài)效果(思路詳解)

    這篇文章主要介紹了Android自定義view之利用drawArc方法實現(xiàn)動態(tài)效果,drawArc方法包含了五個參數(shù),具體細節(jié)在本文中給大家提到過,需要的朋友可以參考下
    2021-08-08

最新評論

峨眉山市| 长宁区| 汉沽区| 乌海市| 兰溪市| 定州市| 海兴县| 澜沧| 新和县| 泰来县| 繁昌县| 漳浦县| 临江市| 铁力市| 中宁县| 神农架林区| 大洼县| 石门县| 孝昌县| 银川市| 菏泽市| 敦化市| 敦化市| 新蔡县| 青铜峡市| 安新县| 宜城市| 濮阳县| 陇南市| 故城县| 昌黎县| 安塞县| 乌海市| 巴南区| 孝感市| 呼图壁县| 博爱县| 盐城市| 时尚| 那曲县| 宜川县|