-
Notifications
You must be signed in to change notification settings - Fork 332
FAQ
moagrius edited this page Jan 11, 2014
·
11 revisions
- How do I use from XML?
- You don't. Since at least 2 method calls are required to have an actionable widget, inflating from XML didn't seem like it was mission-critical. If you'd like to fork a patch, I'd be happy to merge.
- I'm using large Paths and am getting crashes or ANRs
- EDIT: TileView now supports custom path drawing implementation. Just extend DrawablePath and pass those instances to http://moagrius.github.io/TileView/com/qozix/tileview/TileView.html#drawPath(com.qozix.tileview.paths.DrawablePath).
The built-in path drawing mechanism uses Canvas.drawPath, which is notably inefficient. Each path is tested with .quickReject before it's drawn, but that's about it. Canvas.drawLines is much more efficient, but looks poor with Paint more complex than a single pixel. If you need larger paths, consider writing your own implementation (with Canvas.drawLines, or a custom bitmap), and adding it to the View tree of the TileView. You can listen for scale changes and react appropriate in whatever fashion makes the most sense for you implementation. - Tiles aren't being rendered
- This is probably due to a caught out-of-memory exception... the notorious "bitmap exceeds vm budget". These are caught (and discarded) in the default implementation but you're free free to provide your own. In general, it's very unlikely you'll have a tile missing if you've got a well-considered setup. The widget only displays the tiles that are visible. If you're missing some, make sure you're using enough tile sets: a tile set that scales down a lot will need to render lots of small tiles, but each will take up as much memory as it would at full size. If you're seeing lots of small tiles, then you should probably add another tile set at half the size. You can also try smaller individual tiles (256 is default, but any size is supported - try 128).
- When the device sleeps, I get a crash or ANR when waking.
- Make sure your call `TileView.clear()` in your Activity's `onPause` method, and `TileView.resume()` in the Activity's `onResume`.
- When I use slideToAndCenter or moveToAndCenter, it doesn't center...
- Both the centering methods use the dimensions of the View to figure out where center should be. This is not available during onCreate (or similar methods); height and width will be returned as 0, so no offset will be applied. This is not a TileView limitation, it how the Android framework layout mechanism is ordered. For most devices, you can just .post() a Runnable in onCreate to do what you want - (again, in *most* devices) this Runnable won't run() until layout's done. For devices that don't respect this, AFAIK there's no "clean" way to get around it - you can count layout passes and compare it getChildCount in onLayout, but that's clunky at best.
- How do I maintain the center point while setting scale?
-
public void setScaleAndMaintainCenter( double scale ) {
int centerOffsetX = (int) ( tileView.getWidth() * 0.5f ); int centerOffsetY = (int) ( tileView.getHeight() * 0.5f ); Point scroll = new Point( tileView.getScrollX(), tileView.getScrollY() ); scroll.offset( centerOffsetX, centerOffsetY ); double deltaScale = scale / tileView.getScale(); int x = (int) ( scroll.x * deltaScale ) - centerOffsetX; int y = (int) ( scroll.y * deltaScale ) - centerOffsetY; scroll.set( x, y ); tileView.setScale( scale ); tileView.scrollToPoint( scroll );
}
TODO: