android - 如何在 tileview android 中单击并在其上填充位图时选择特定图 block

标签 android tiles

我正在使用 TileView 使用 Tileview 显示大图像图书馆

现在我想在特定图 block 上单击时在矩形边界中显示一个圆圈。

如何获取点击了哪个图 block ?以及如何在该图 block 上方显示 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()

这将返回您当前视口(viewport)中的磁贴,每个磁贴都知道它的左/右和上/下边界,因此您可以遍历磁贴并找到您单击的那个。

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

由于您知道所有事物的 rect,因此您可以简单地添加 HotSpot,在库中,HotSpot 似乎是支持点击监听器的 rect。

您可以像这样添加热点:

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 ,就像这样

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

关于android - 如何在 tileview android 中单击并在其上填充位图时选择特定图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31956190/

相关文章:

java - tmpFile.renameTo(classFile) 失败错误

java - 用瓷砖创建一个圆圈

Android - 使用 Theme.AppCompat 不显示操作栏

android - 键盘关闭时 Recyclerview 崩溃

android - 从 sqlite 按日期升序排序列表

java - NoClassDefFound错误: org/apache/tiles/TilesApplicationContext Error with Spring Servlet

java - 在 Spring 过滤器中设置 View 名称

通过 Leaflet 使用本 map block 的 HTML 离线 map

android - Android Studio中同步Gradle项目时发生错误

android - 通过android NDK编译tesseract