java - 为什么在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>`
但是在不同的设备上结果仍然不同。它没有正确缩放和旋转。我究竟做错了什么?
解决方案
推荐阅读
- spring-cloud-config - 没有定义 spring.config.import 属性
- math - 我如何用分析师数量和他们的评级与条目数量的权重来标准化股票评级?
- reactjs - 流式传输图像以响应页面
- python - 比较数据帧中的列并将其放入另一个
- html - 使用 Treeview 进行主动导航不起作用!- 惯性JS Laravel Vue
- r - 如何通过将现有行的值与 R dplyr 组合来将行添加到数据框
- python - 为什么以及如何:缺少 python3 的符号链接?
- angular - 如何使角度打字稿功能在html元素中工作
- php - Nextcloud 的慢速下载在 60 秒后终止
- sql - node.js sql 将 JSON 插入数据库