Skip to content

Commit c96a445

Browse files
committed
update calculateWidthHeightRatio ...
1 parent 819f8a0 commit c96a445

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ Anchor point positioning ImageView For [Android](https://raw.githubusercontent.c
66

77
Introduction
88
============
9-
An ImageView that anchors points according to the pixels,
9+
一个可以锚点定位的 ImageView(根据像素点)
10+
Demo 中通过 AnchorImageView 简单的实现了一个课本点读的功能
11+
[An ImageView that anchors points according to the pixels,
1012
locates the anchored area.
1113
Demo shows a simple Click on the content area,
12-
in the book to respond to the action.
14+
in the book to respond to the action.]
1315
License
1416
=======
1517
MIT License

src/main/java/com/jcodeing/anchorimageview/widget/AnchorImageView.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ protected void disposeEvent(MotionEvent e) {
231231

232232
@Override
233233
public void setImageBitmap(Bitmap bm) {
234-
setWidthHeightRatio((float) parentWidth * 1f / (float) bm.getWidth(), (float) parentHeight * 1f / (float) bm.getHeight());
235234
super.setImageBitmap(bm);
235+
calculateWidthHeightRatio();
236236
}
237237

238238
// ============================@Set/Get@============================
@@ -241,9 +241,9 @@ public void setParentWidthHeight(int width, int height) {
241241
parentHeight = height;
242242
}
243243

244-
public void setWidthHeightRatio(float widthRatio, float heightRatio) {
245-
this.widthRatio = widthRatio;
246-
this.heightRatio = heightRatio;
244+
public void calculateWidthHeightRatio() {
245+
widthRatio = (float) parentWidth / getDrawable().getIntrinsicWidth();
246+
heightRatio = (float) parentHeight / getDrawable().getIntrinsicHeight();
247247
}
248248

249249
public void setCurrentClickAnchor(Anchor anchor) {
@@ -383,10 +383,10 @@ class AnchorCutProcess extends Thread {
383383

384384
rectClickAnchor.set(leftP * widthRatio, topP * heightRatio, rightP * widthRatio, bottomP * heightRatio);
385385

386-
leftDMovElement = leftD * 1f / diffMovElementTotal;
387-
rightDMovElement = rightD * 1f / diffMovElementTotal;
388-
topDMovElement = topD * 1f / diffMovElementTotal;
389-
bottomDMovElement = bottomD * 1f / diffMovElementTotal;
386+
leftDMovElement = leftD / diffMovElementTotal;
387+
rightDMovElement = rightD / diffMovElementTotal;
388+
topDMovElement = topD / diffMovElementTotal;
389+
bottomDMovElement = bottomD / diffMovElementTotal;
390390
}
391391

392392
public void run() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy