- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当给定值发生变化时,我需要旋转一个针形图像。获得的值是随机的。
我在 xml 中创建了图像,它是一个 ImageView 。
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false" >
<ImageView
android:id="@+id/meter_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_marginTop="54dp"
android:src="@drawable/gauge_meter" />
<ImageView
android:id="@+id/meter_needle_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/meter_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:src="@drawable/meter_needle" />
</RelativeLayout>
我使用以下代码进行了旋转,但它不是在其底轴上旋转
RotateAnimation rpmNeedleDeflection = new RotateAnimation((float) (0.5f), (float) (90), 130, 0);
rpmNeedleDeflection.setDuration(500);
rpmNeedleDeflection.setFillAfter(true);
rpmArrowView.startAnimation(rpmNeedleDeflection);
我仍在弄清楚旋转是如何工作的,在我的例子中,我需要根据速度设置角度。但是现在给定一个值,我如何让它从针的底部转向并绕着那个轴?
编辑:针是31*113, basemap 是224*224
最佳答案
要解决这个问题,您有 2 个选择:
选项 1:
将您的针图像调整为与背景图像完全相同的大小,即从 31 x 113 到 224 x 224。执行此操作时,确保您实际上不只是将图像缩放到这个大小(这将导致奇怪的拉伸(stretch)针图像)。你要做的是创建一个 224x224 的透明图像,并将原始尺寸 (31x113) 的针图像复制粘贴到这个新的透明图像中,使针的基圆正好位于 224x224 透明图像的中心,并且与“虚构”背景正确对齐。将图像保存并导出为 png 格式,并将此图像用作您的针图像。
您现在需要做的就是确保 2 张图像彼此完美对齐。这应该不难,因为它们的大小应该相同。当您旋转针图像时,您将获得所需的结果。
选项 2:
假设您无法调整图像的大小 - 可能是因为它被您的程序的其他部分使用,或者其他一些原因。您的第二个选择是定位图像,并使用轴心点来确保它通过代码正确定位。
为此,您需要将图像水平和垂直居中,您需要对齐它,使针的底部直接位于背景的中心。
就定位而言,需要反复尝试才能使其完美,但您似乎已经确定了该部分。你缺少的是旋转的枢轴点。让我们看看如何计算它:
数学时间!
我猜测直径等于图像的宽度,因为它是最宽的部分。这意味着针的水平中心位于图像宽度的一半:
final int pivotX = rpmArrowView.getMeasuredWidth() / 2;
图片的垂直中心应该是一样的,除了从图片的底部:
final int pivotY = rpmArrowView.getMeasuredHeight() - rpmArrowView.getMeasuredWidth() / 2;
现在,在制作动画之前,请确保设置轴心点:
rpmArrowView.setPivotX(pivotX);
rpmArrowView.setPivotY(pivotY);
然后动画:
rpmArrowView.animate().rotation(someDegree).setDuration(someDuration)
就是这样!可能需要进行更多调整才能获得完美的定位,但这就是它的要点。
希望这些选项之一对您有所帮助。
关于android - 针绕其指针头旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29858571/
我正在尝试将多个项目转换为 classy-prelude眼下。虽然大多数行为对我来说似乎相当简单,但 (head . head) 在简单的 2D 列表上给出了神秘的错误。 考虑以下 GHCi sess
我创建了这个类来从请求中获取 Header 值。 public class AuthenticationHeader { private static IHttpContextAccesso
这里有两段代码。 工作: joins :: [String] -> String -> String joins [] _ = "" joins [x] _ = x joins xs d = head
我是编程新手,正在Windows中使用vscode并通过Mingw 64进行编译。尝试了数天后,我要求对此问题做出解答。我用谷歌搜索了很多次。这是我的项目树的外观。请帮助我包括并将 libA 链接到
我正在研究 Ninety-Nine Scala Problems 的 P07 问题: P07 (**) Flatten a nested list structure. Example: scala>
这里有两段代码。 工作: joins :: [String] -> String -> String joins [] _ = "" joins [x] _ = x joins xs d = head
我正在使用现成的欧洲 cookie 政策脚本。问题是,我的 Hubspot CMS 只允许所有内容的全局标题或每个页面的单独标题。我们有 120 个页面,很难手动定义它,但我们需要一个用于德语页面的脚
Solaris 10 SPARC Sun Studio C 编译器 12.3 在 SPARC64 机器上,如果您访问一个在相关 4 或 8 字节边界上未正确对齐的变量,您将获得核心转储。这需要编码人员
我正在尝试从服务器列表中获取 apache 版本。我正在考虑解析 header ,但是我无法发送 HEAD 但它可以与 GET POST 等一起使用。 这是我的代码: import java.io.B
嗨,我是 github 的新手,当我对代码做了一些更改然后 merge 到上游时,如果有任何冲突,它将执行以下操作。 Auto-merging Global.asax.cs CONFLICT (con
例如,获取偏移量 Y 之后的前 X 行的建议方法是什么?我目前正在做的是: offset, limit = 2, 2 df=pd.DataFrame([{'a':1}, {'a': 2}, {'a':
当我在R块 header 中插入长标题等内容时,能够将 header 拆分为多行会很好。 有没有简单的方法可以做到这一点? 例如。: ```{r, echo=FALSE, warning=FALSE,
我刚刚开始使用 Erlang(虽然有一些 lisp 背景)并且有一个关于列表模式匹配的问题。 如果我说 [Head | Tail] = [1, 2, 3]. 然后我得到 Head = 1 Tail =
我的 index.php 文件开头有这段代码: if ( !isset($_GET['cat']) ) die(header("Location: ?cat=top")
对第 3 方应用程序进行一些 SOAP 调用。他们提供此 soap header 作为应用程序期望的示例。如何在 PHP 中创建这样的 SOAP header ?
我对 git 仓库下的文件做了一些更改,我使用 git commit 提交了文件 然后我尝试使用 git push origin master 推送到 master,它返回了 Everything u
我刚刚尝试从 url 下载 webp 图像,但是当我尝试处理存储的图像时,我发现了一些不同的东西。 如果我从浏览器下载图像,它可以使用 x/image/webp 包解码,但如果我使用 http.Get
这是来自 slices 的略微修改的代码 var buffer [256] byte func SubtractOneFromLength(slice []byte) []byte { sli
在 Linux 中是否有一种方法可以请求 Head 或 Tail 但要忽略额外的记录偏移量。 例如,如果文件 example.lst 包含以下内容: row01 row02 row03 row04 r
代码: /* * File: problem5.c * Author: levihackwith * Description: Write a Pop() function that is th
我是一名优秀的程序员,十分优秀!