Android 图片定点 图片加文字组合 适配问题

Android  图片加文字结合组成碰到的适配问题

适配机型的话就测试了两款手机,,,,之前 用其他方法都不好使的时候用这个就解决了

Android 图片定点 图片加文字组合 适配问题_第1张图片

public class MyImagView extends View {
    private Paint paintWhite,paintRed;//第一个图定点坐标
    private String textContentOne = "Holle", textNumberOne = "Word";
    private int mWidth; // 控件宽度
    private int mHeight; // 控件高度

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

    public MyImagView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyImagView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }


    public void setAddrTextOne(String textContentOne, String textNumberOne){
        this.textContentOne = textContentOne;
        this.textNumberOne = textNumberOne;
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        mWidth = getWidth();
        mHeight = getHeight();
        setBackgroundResource(R.mipmap.img_king);
    }

    private void initPaint() {
        paintWhite = new Paint(Paint.ANTI_ALIAS_FLAG);
        paintWhite.setColor(Color.WHITE);
        paintWhite.setTextSize(24);
        paintWhite.setStrokeWidth(2f);

        paintRed = new Paint(Paint.ANTI_ALIAS_FLAG);
        paintRed.setColor(Color.RED);
        paintRed.setTextSize(24);
        paintRed.setStrokeWidth(2f);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //设置定点文字   改变x,y大小决定文字移动区域
        canvas.drawText(textContentOne, mWidth / 4.3f, mHeight / 1.6f, paintWhite);
        canvas.drawText(textNumberOne, mWidth / 5.57f, mHeight / 2.00f, paintRed);
    }
}

你可能感兴趣的:(图片定点,图片组合)