安卓:ShowCase View只显示一次且重复动画

3

我正在我的Fragment中使用ShowCase View library。我展示了一个手势动画,应该在用户按下OK按钮之前一直重复显示。但它只显示了一次。

此外,Showcase每次创建Fragment时都会显示,而不仅仅是一次。

我的代码如下:

public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //get display size for slide over screen
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        Point p = new Point();
        display.getSize(p);

        if(!is_tablet()){
            // ShowView Tutorial if on smartphone
            ViewTarget target = new ViewTarget(getView());
            ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
            //can only dismiss by button click
            co.hideOnClickOutside = false;
            //show only once
            co.shotType = ShowcaseView.TYPE_ONE_SHOT;
            sv = ShowcaseView.insertShowcaseView(target, getActivity(),
                    R.string.showcase_detail_title, R.string.showcase_detail_message,co);
            // remove circle
            sv.setShowcaseIndicatorScale(0);
            // set black background
            sv.setBackgroundColor(getResources().getColor(R.color.black));
            // make background a bit transparent
            sv.setAlpha(0.9f);
            // show PullToRefreshGesture
            sv.animateGesture(0, p.y / 2, p.x, p.y / 2);
        }

所使用的布局:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<mypackage.PullToRefresh.PullToRefreshListView
android:id="@id/android:list"
android:layout_height="match_parent"
android:layout_width="match_parent" 
android:divider="@android:color/transparent"
android:dividerHeight="10dp"
android:layout_margin="10dp"/>

</LinearLayout>

你能发布你的布局吗? - Umit Kaya
3个回答

6
我是这样解决的:
  1. 为了在安装后仅执行一次,我按照此帖的建议操作。
  2. 为了重复播放动画,我使用了此帖中提供的代码。
现在,ShowcaseView仅在安装后出现一次,并且手势动画将持续显示,直到按钮被点击。

2
 /**
     * Set the ShowcaseView to only ever show once.
     *
     * @param shotId a unique identifier (<em>across the app</em>) to store
     *               whether this ShowcaseView has been shown.
     */
    public Builder singleShot(long shotId) {
        showcaseView.setSingleShot(shotId);
        return this;
    }

0

重复动画多次:

sv.setRepeatCount(number);

对于无限的情况:

sv.setRepeatCount(Animation.INFINITE);
sv.setRepeatMode(Animation.INFINITE);

在你的布局中:

android:repeatMode="reverse"

我将布局添加到了原始帖子中。如果我尝试添加行 sv.setRepeatCount(Animation.INFINITE);,它会说“对于 ShowCase View 类型未定义 setRepeatCount()”。 - Mokkapps

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接