如何 select 单击特定图块并在 tileview android 中膨胀位图

How to select a particular tile when clicked and inflate a bitmap on it in tileview android

我正在使用 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();
        }
    };
}

在我看来,如果不修改代码,您将无法在库中进行一些挖掘(尽管您可能不需要获取该图块,请参阅选项 2 中的更多信息),这是可行的尽管它是开源的,因此您可以在本地进行修改并从那里开始。

第一个选项:

您需要的第一个修改:

https://github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/detail/DetailManager.java

添加以下代码:

public DetailLevel getCurrentDetailLevel() {
    return currentDetailLevel;
}

https://github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/TileView.java

public DetailManager getDetailManager() {
    return detailManager;
}

这会在 DetailLevel 中公开您需要的方法,例如

public LinkedList<Tile> getIntersections()

这将 return 您当前视口中的图块,每个图块都知道它受 left/right 和 top/bottom 限制,因此您可以遍历图块并找到您想要的那个点击了。

第二个选项(可能的话推荐):

既然你知道所有东西的 rects,你可以简单地添加 HotSpots,在库中 HotSpots 似乎是支持点击侦听器的 rects。

您可以这样添加热点:

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
 }

更多信息: 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);