【问题标题】:Move, rotate and scale text using custom layout in android在 android 中使用自定义布局移动、旋转和缩放文本
【发布时间】:2015-07-24 10:43:17
【问题描述】:

嗨,我想做这样的事情

当用户按下旋转图标时,包含在框中的文本应逐渐旋转并使用缩放图标,文本应调整大小。

现在我正在使用此代码将 textview 移动到屏幕上的任何位置

 private int _xDelta;
private int _yDelta;

@Override
public boolean onTouch(View view, MotionEvent event) {


    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
            _xDelta = X - lParams.leftMargin;
            _yDelta = Y - lParams.topMargin;
            break;
        case MotionEvent.ACTION_UP:
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            break;
        case MotionEvent.ACTION_POINTER_UP:
            break;
        case MotionEvent.ACTION_MOVE:
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
            layoutParams.leftMargin = X - _xDelta;
            layoutParams.topMargin = Y - _yDelta;
            layoutParams.rightMargin = -250;
            layoutParams.bottomMargin = -250;
            view.setLayoutParams(layoutParams);
            break;
    }
    elementslayout.invalidate();
    return true;
}

它工作正常。 长按 textview 我想显示带有旋转和缩放图标的布局。 我的问题是,

 How to create this type of layout for textview and do rotate and scale accordingly?

我见过很多使用矩阵进行旋转和缩放的代码,例如 http://judepereira.com/blog/multi-touch-in-android-translate-scale-and-rotate/

但是这里不知道怎么用。

【问题讨论】:

  • 你有没有发现什么有用的东西?如果是,请在此处发布您的答案。
  • @n1m1 如果您有解决方案,请发布答案

标签: android rotation scaletransform


【解决方案1】:

我也想做同样的事情,旋转、缩放以及一起移动 textview。我在这里找到了文本旋转的链接。

Android Two finger rotation

这对于文本旋转非常有效。你只需要添加

txt.setRotation(-angle);

在 onRotation 方法中。可能对你有帮助。

【讨论】:

    猜你喜欢
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 2012-09-17
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多