ShowCaseView错误地呈现

时间:2014-08-05 18:34:35

标签: android android-layout android-activity android-view

我在我的Android应用程序中使用showCaseView legacy(具有手的动画)。但是,这个手势似乎并没有从视图开始“相对”。相反,它似乎绝对是屏幕。这是我正在使用的以下内容:

 final ShowcaseView sv;
      ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
      co.hideOnClickOutside = false;
    co.block=true;
      sv = ShowcaseView.insertShowcaseView(R.id.pen, this," R.string.showcase_title"," R.string.showcase_message", co);
      View v=(View)findViewById(R.id.pen);
     sv.animateGesture(0, 0, 0, -500, false);

这是我的模拟器的顶部,动画STARTS来自这里: enter image description here 这显示了屏幕左上角的一只手。 (我的猜测是视图的位置返回0.

有什么问题?

2 个答案:

答案 0 :(得分:0)

你最好的选择可能是使用DisplayMetrics来放手,这就是我所做的,而且似乎运作良好。

DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
int height = displaymetrics.heightPixels;
        int width = displaymetrics.widthPixels;

        float offsetEndY = height / 2 + 50;
        float offsetEndX = -width;
        float offsetStartY = height / 2 + 50;
        float offsetStartX = -width / 2;

        if (sv == null) {

            sv = ShowcaseView.insertShowcaseView(width, 0, activity, "Menu", "Swipe to access more options", mOptions)
                    .setTextColors(Color.BLUE, Color.BLACK);
            sv.animateGesture(offsetStartX, offsetStartY, offsetEndX, offsetEndY);

答案 1 :(得分:0)

我遇到了同样的问题,而且我在不同阶段记录展示位置时发现,在调用show()之后的一些(非常短的)时间内,正确地计算了正确的位置。 当我打电话时

showcaseView.show();
showcaseView.animateGesture(0, 0, 0, -400);

这个DIDN' T work。

简单的解决方案是显示手势有一些延迟(在我的情况下200毫秒足够 - 在许多设备上测试):

showcaseView.show();
showcaseView.postDelayed(new Runnable() {
    @Override
    public void run() {
        showcaseView.animateGesture(0, 0, 0, -400);
    }
}, 200);
相关问题