我使用 编写了用于旋转文本的代码SurfaceView
,这没关系。现在我想编辑SurfaceView
我之前所做的文本。将出现一个editText
并且可以编辑,但是当我旋转文本时,textView
它不会随文本一起旋转。
我用于添加和旋转的代码editText
如下:
if(editText!= null)
relativeLayout.removeView(editText);
else {
editText = new EditText(MainActivity.this);
editText.setText(rectF.getText());
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams((int) rectF.getBounds().width(),
(int) rectF.getBounds().height());
params.leftMargin = (int) rectF.getBounds().left;
params.topMargin = (int) rectF.getBounds().top;
editText.setLayoutParams(params);
Animation an = new RotateAnimation(0,rectF.getAngle());
an.setDuration(0);
an.setRepeatCount(0);
an.setZAdjustment(Animation.ZORDER_TOP);
an.setFillAfter(true);
editText.setAnimation(an);
relativeLayout.addView(editText);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService (Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
editText.setOnKeyListener( new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
saveEditText();
return true;
}
return true;
}
private void saveEditText() {
txt2.setText(editText.getText().toString());
InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
relativeLayout.removeView(editText);
}
});
}