微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在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 举报,一经查实,本站将立刻删除。