【问题标题】:How to rotate EditText manually in Android如何在 Android 中手动旋转 EditText
【发布时间】:2012-10-01 10:27:27
【问题描述】:

我有一个图像编辑 android 应用程序,其中我使用自定义 EditTextView 放置在 ImageView 上。这个图像视图也是一个自定义视图,可以旋转、缩放、拖动等......现在,我想拖动这个EditText 并在单击按钮时旋转。这是我的自定义EditTextView

public class TemplateTextView extends EditText {
    private static float angle;
    // We can be in one of these 3 states
    private int mode = NONE;
    // Remember some things for zooming
    PointF start = new PointF();
    PointF mid = new PointF();
    PointF startMargins = new PointF();
    float oldDist = 1f;

    /**
     * Constructor for TemplateTextView
     * 
     * @param context
     * @param attrs
     * @param defStyle
     */
    public TemplateTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        // mWindowManager = (WindowManager)
        // context.getSystemService(Context.WINDOW_SERVICE);
    }

    /**
     * Constructor for TemplateTextView
     * 
     * @param context
     * @param attrs
     */
    public TemplateTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    }

    /**
     * Constructor for TemplateTextView
     * 
     * @param context
     */
    public TemplateTextView(Context context) {
        this(context, null);
    }
}

EdittextView 在长按时被拖拽。如何旋转和拖动此视图?

【问题讨论】:

标签: android android-ui custom-component


【解决方案1】:

对于旋转,您可以在 TemplateTextView 的 onDraw-Method 中简单地执行此操作:

@Override
  protected void onDraw(Canvas canvas) {
    canvas.rotate(angle, canvas.getClipBounds().right/2, canvas.getClipBounds().bottom/2);
    super.onDraw(canvas);
  }

干杯,伙计

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 2018-10-27
    • 2021-07-26
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    相关资源
    最近更新 更多