Android 安卓;“拖放阴影”;以及视图位置、缩放和旋转
各位。我确实有两个问题无法解决。我制作了两个视频来帮助理解: (a) (b) 这是我的第一个安卓应用程序,所以我不知道我做的是否正确Android 安卓;“拖放阴影”;以及视图位置、缩放和旋转,android,android-layout,android-imageview,android-canvas,android-view,Android,Android Layout,Android Imageview,Android Canvas,Android View,各位。我确实有两个问题无法解决。我制作了两个视频来帮助理解: (a) (b) 这是我的第一个安卓应用程序,所以我不知道我做的是否正确 查看缩放和旋转(绘制直线和曲线)。 我有两种类型的对象要进行更改:向量可绘制(是xml文件)和在运行时绘制的线。我不认为矢量绘图在这个问题上是错误的,只是行。这些元素是使用以下XML扩展的视图: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http:/
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/element_generic_root"
android:background="#0000ff">
<!--android:background="@android:color/transparent">-->
<!-- generic android:src just to show on xml preview. -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/element_generic_image"
android:src="@drawable/pencil"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="18dp"
android:layout_height="18dp"
android:id="@+id/element_generic_resize"
android:background="@drawable/button_resize"
android:layout_alignBottom="@+id/element_generic_image"
android:layout_toEndOf="@+id/element_generic_image"
android:layout_marginLeft="6dp"
android:adjustViewBounds="true"/>
<ImageButton
android:layout_width="18dp"
android:layout_height="18dp"
android:id="@+id/element_generic_rotate"
android:background="@drawable/rotate"
android:layout_alignTop="@+id/element_generic_image"
android:layout_toEndOf="@+id/element_generic_image"
android:layout_marginLeft="6dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
对不起,这篇文章太长了,但我正在尽可能让大家理解我的意思
提前感谢,,
安德烈·文德拉米尼
public void resize() {
float scale = moveResize / DEFAULT_WIDTH;
float height = scale * DEFAULT_HEIGHT;
float nw = moveResize < MIN_WIDTH ? MIN_WIDTH : moveResize;
float nh = height < MIN_HEIGHT ? MIN_HEIGHT : height;
double rad = Math.toRadians(getView().getRotation());
double cos = Math.cos(rad);
double sin = Math.sin(rad);
double difh = (nh - getHeight()) * cos;
double difw = (nw - getWidth()) * sin;
setWidth(nw);
setHeight(nh);
if(nh == MIN_HEIGHT) difw = 0;
getView().setX((float) (getView().getX() + (difw / 2)));
getView().setY((float) (getView().getY() - (difh / 2)));
build();
}
public class ElementDragShadow extends View.DragShadowBuilder {
private int width;
private int height;
public ElementDragShadow(View view) {
super(view);
double rotationRad = Math.toRadians(getView().getRotation());
int w = (int) (getView().getWidth() * getView().getScaleX());
int h = (int) (getView().getHeight() * getView().getScaleY());
double s = Math.abs(Math.sin(rotationRad));
double c = Math.abs(Math.cos(rotationRad));
width = (int) (w * c + h * s);
height = (int) (w * s + h * c);
}
@Override
public void onDrawShadow(Canvas canvas) {
canvas.scale(getView().getScaleX(), getView().getScaleY(), width / 2, height / 2);
canvas.rotate(getView().getRotation(), width / 2, height / 2);
canvas.translate((width - getView().getWidth()) / 2, (height - getView().getHeight()) / 2);
super.onDrawShadow(canvas);
}
@Override
public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
shadowSize.set(width, height);
shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2);
// shadowTouchPoint.set(shadowSize.x, shadowSize.y);
}
}