旋转的editText无法正确显示

时间:2012-06-04 10:01:16

标签: android surfaceview android-edittext

我使用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);
        }
    });
}

0 个答案:

没有答案