预览
使用
TextStickerView mTextStickerView = new TextStickerView(this, null);
mTextList.add(mTextStickerView);
RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mTextStickerView.setLayoutParams(layoutparams);
mRlContainer.addView(mTextStickerView);]
TextStickerView
/**
* 文本贴图处理控件
*/
public class TextStickerView extends View {
protected static final String TAG = TextStickerView.class.getSimpleName();
public final int TEXT_SIZE_DEFAULT = getResources().getDimensionPixelSize(R.dimen.fontsize_default);
// public final int PADDING = getResources().getDimensionPixelSize(R.dimen.font_padding);
public final int PADDING = 32;
// public final int STICKER_BTN_HALF_SIZE = getResources().getDimensionPixelSize(R.dimen.sticker_btn_half_size);
public final int STICKER_BTN_HALF_SIZE = 30;
private String mText = getResources().getString(R.string.input_hint); //给贴图文本赋个初始值
private TextPaint mPaint = new TextPaint();
private Paint debugPaint = new Paint();
private Paint mHelpPaint = new Paint();
private Rect mTextRect = new Rect();// warp text rect record
private RectF mHelpBoxRect = new RectF();
private Rect mDeleteRect = new Rect();//删除按钮位置
private Rect mRotateRect = new Rect();//旋转按钮位置
private RectF mDeleteDstRect = new RectF();
private RectF mRotateDstRect = new RectF();
private Bitmap mDeleteBitmap;
private Bitmap mRotateBitmap;
private int mCurrentMode = IDLE_MODE;
//控件的几种模式
private static final int IDLE_MODE = 2;//正常
private static final int MOVE_MODE = 3;//移动模式
private static final int ROTATE_MODE = 4;//旋转模式
private static final int DELETE_MODE = 5;//删除模式
private EditText mEditText;//输入控件
public int layout_x = 0;
public int layout_y = 0;
private float last_x = 0;
private float last_y = 0;
public float mRotateAngle = 0;
public float mScale = 1;
private boolean isInitLayout = true;
private boolean isShowHelpBox = true;
private float dx;
private float dy;
private long currentTime;
//设置字体
private Typeface type;
//设置画笔的透明度
private int mAlpha = 255;
public TextStickerView(Context context, Typeface type) {
super(context);
initView(context, type);
}
public TextStickerView(Context context, AttributeSet attrs, Typeface type) {
super(context, attrs);
initView(context, type);
}
public TextStickerView(Context context, AttributeSet attrs, int defStyleAttr, Typeface type) {
super(context, attrs, defStyleAttr);
initView(context, type);
}
public void setEditText(EditText textView) {
this.mEditText = textView;
// //设置特殊字体
// mEditText.setTypeface(type);
}
private void initView(Context context