如何在tileview android中单击时选择特定的图块并在其上膨胀位图?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (24)

现在我想在特定的瓦片上显示​​一个圆形的边界。

如何获得点击哪个图块:

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();
        }
    };
}
提问于
用户回答回答于

第一个选项:

你需要第一次修改:

https://github.com/moagrius/TileView/blob/master/src/com/qozix/tileview/detail/Det​​ailManager.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()

第二选项(如果可能,建议使用):

既然你知道所有东西的rects,你可以简单地加入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
 }

该库支持标记,您可以简单地添加一个图像视图,将圆圈作为标记,就像这样:

ImageView view = new ImageView (this);
view.setImageResource(circleId);
tileView.addMarker (view, tile.x, tile.y);

扫码关注云+社区