在android中的视图上应用矩阵变换时,为什么矩阵变换在不同的设备上有所不同?

问题描述

我正在使用贴纸视图库 https://github.com/wuapnjie/StickerView。我在 sticker.getMatrix() 方法的帮助下保存了所有贴纸的位置。但是当我在另一台具有不同 DPI 的设备上从数据库加载值时,转换完全不同。

在进一步研究中,我发现为了翻译,我需要转换 px 来做。所以我将第 2 个和第 5 个索引(基于 0 的索引系统)更改为 dp。在加载值时,我将其转换回像素

matrix[2] = DensityUtils.px2dp(context,originalmatrix[2]); matrix[5] = DensityUtils.px2dp(context,originalmatrix[5]);

和加载时

if(x==2||x==5) { val=DensityUtils.dp2px(GreetingsMakerActivity.this,val); }

这里是布局文件,以防万一

`<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/top_parent"><RelativeLayout
android:id="@+id/rl_parent"
android:layout_alignParentTop="true"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"><com.example.stickerview.sticker.StickerView
android:id="@+id/greetings_frame"
app:showBorder="false"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
app:showIcons="true"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/greetings_image_view"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.example.stickerview.sticker.StickerView>
</RelativeLayout>
</RelativeLayout>`

但在不同设备上的结果仍然不同。它没有正确缩放和旋转。我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)