1 字体适配

    private void textSizeAdaptive() {        //1.获取当前设备的屏幕大小        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();        //2.计算与你开发时设定的屏幕大小的纵横比(这里假设你开发时定的屏幕大小是480*800)        int screenWidth = displayMetrics.widthPixels;        int screenHeight = displayMetrics.heightPixels;        float ratioWidth = (float) screenWidth / 1080;        float ratioHeight = (float) screenHeight / 1920;        ratio = Math.min(ratioWidth, ratioHeight);        if (ratioWidth != ratioHeight) {            if (ratio == ratioWidth) {                offsetLeft = 0;                offsetTop = Math.round((screenHeight - 1920 * ratio) / 2);            } else {                offsetLeft = Math.round((screenWidth - 1080 * ratio) / 2);                offsetTop = 0;            }        }        //3.根据上一步计算出来的最小纵横比来确定字体的大小(假定在1080*1920屏幕下字体大小设定为35)        TEXT_SIZE = Math.round(textsize * ratio);    }
  1. onDraw
@Override    protected synchronized void onDraw(Canvas canvas) {        // TODO Auto-generated method stub        super.onDraw(canvas);        canvas.save();        mText = (getProgress() * 100 / getMax()) + "%";        Rect rect = new Rect();        mPaint.getTextBounds(leftText, 0, leftText.length(), rect);        int y = (getHeight() / 2) - rect.centerY();        //在进度条上画上自定义文本        canvas.drawText(leftText, 5, y, mPaint);        int width = rect.width();        //进度        float radio = getProgress() * 1.0f / getMax();        float progressPosX = (int) (mRealWidth * radio);        //起始点        int beginX = 10 + width;        //结束点        float textWidth = mPaint.measureText(mText);        float endX = mRealWidth - textWidth;        if (beginX > progressPosX- textWidth) {            canvas.drawText(mText, beginX, y, mPaint);        } else if (progressPosX- textWidth > endX) {            canvas.drawText(mText, endX, y, mPaint);        } else {            canvas.drawText(mText, progressPosX - textWidth, y, mPaint);        }        canvas.restore();    }

下载地址 http://download.csdn.net/download/liudao7994/10130885

更多相关文章

  1. android radioButton 改变圆圈大小
  2. Android(安卓)露珠/水滴 拖拽 效果实现
  3. Android中获取屏幕信息的几种方式
  4. Android(安卓)Screen Monitor抓取真机屏幕(在电脑显示屏幕显示过
  5. Android(安卓)自定义view 和 onMeasure方法介绍
  6. Android在onCreate或者在Fragment的onCreateView中获取控件、屏
  7. Mac 进行 android 真机调试
  8. Android:使用canvas绘制饼状统计图(自动适应条目数量/大小)
  9. Android利用ViewFlipper实现屏幕切换动画效果

随机推荐

  1. Android(安卓)- Binder机制 - Binder框架
  2. Android下基于XML的Graphics shape使用方
  3. LinearLayout和RelativeLayout的特殊属性
  4. Android(安卓)layout属性大全
  5. Android布局文件layout.xml的一些属性值
  6. Android:inputType参数类型说明
  7. Android常用布局属性
  8. 配置文件:android:inputType参数类型说明
  9. Android设置图片在TextView上、下、左、
  10. android:inputType参数类型说明