我Tileview使用TileView库显示一个大图像
现在我想在特定的瓷砖上显示时在矩形边界显示一个圆圈.
如何点击哪个瓷砖?以及如何显示BitMmap上面的那个瓷砖?
public class LargeImageTileViewActivity extends TileViewActivity {
TileView tileView;
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
// multiple references
tileView = getTileView();
// by disabling transitions, we won't see a flicker of background color when moving between tile sets
tileView.setTransitionsEnabled( false );
// size of original image at 100% scale
tileView.setSize( 2835, 4289 );
// detail levels
tileView.addDetailLevel( 1.000f, "tiles/painting/1000/%col%_%row%.jpg");
tileView.addDetailLevel( 0.500f, "tiles/painting/500/%col%_%row%.jpg");
tileView.addDetailLevel( 0.250f, "tiles/painting/250/%col%_%row%.jpg");
tileView.addDetailLevel( 0.125f, "tiles/painting/125/%col%_%row%.jpg");
// set scale to 0, but keep scaleToFit true, so it'll be as small as possible but still match the container
tileView.setScale( 0 );
// let's use 0-1 positioning...
tileView.defineRelativeBounds( 0, 0, 1, 1 );
// frame to center
frameTo( 0.5, 0.5 );
tileView.addTileViewEventListener( listener );
}
private TileViewEventListenerImplementation listener = new TileViewEventListenerImplementation(){
public void onTap( int x, int y ) {
SampleCallout callout = new SampleCallout(LargeImageTileViewActivity.this);
tileView.slideToAndCenter(x, y);
//Toast.makeText(mContext, "Center " + tempStore.getCenterX() + " " + tempStore.getCenterY(), Toast.LENGTH_SHORT).show();
tileView.addCallout(callout, x, y, -0.5f, -1.0f);
callout.transitionIn();
}
};
}
Run Code Online (Sandbox Code Playgroud)
从我在图书馆中挖掘一下,在我看来,如果没有修改代码你将无法获得平铺(你可能不需要获得平铺,请参阅选项2中的更多内容),这是可行的,因为它是开源的,所以你可以在本地进行修改,然后从那里开始.
第一种选择:
首先需要修改:
在https://github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/detail/DetailManager.java
添加以下代码:
public DetailLevel getCurrentDetailLevel() {
return currentDetailLevel;
}
Run Code Online (Sandbox Code Playgroud)
在https://github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/TileView.java
public DetailManager getDetailManager() {
return detailManager;
}
Run Code Online (Sandbox Code Playgroud)
这会在DetailLevel中公开您需要的方法,例如
public LinkedList<Tile> getIntersections()
Run Code Online (Sandbox Code Playgroud)
这将返回当前视图端口中的Tiles,每个tile都知道它由left/right和top/bottom限定,因此您可以遍历tile并找到您单击的那个.
第二种选择(如果可能,建议):
既然您知道所有事物的所有内容,您可以简单地添加HotSpots,在库中似乎HotSpots是支持点击侦听器的rects.
您可以像这样添加HotSpot:
HotSpot hotSpot = new HotSpot(left, top, right, bottom);
hotSpot.setHotSpotEventListener(this);
tileView.addHotSpot(hotSpot);
....
public void onHotSpotTap(HotSpot hotSpot, int x, int y){
Do your gui update using the supplied hotSpot above
}
Run Code Online (Sandbox Code Playgroud)
更多信息:https: //github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/hotspots/HotSpot.java
添加圆圈
该库支持标记,您只需添加一个图像视图,将圆圈作为标记,就像这样
ImageView view = new ImageView (this);
view.setImageResource(circleId);
tileView.addMarker (view, tile.x, tile.y);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
497 次 |
| 最近记录: |