【问题标题】:Android: ShowCase View show only once and repeat animationAndroid:ShowCase View 仅显示一次并重复动画
【发布时间】:2014-01-21 07:13:35
【问题描述】:

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

此外,每次创建 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>

【问题讨论】:

  • 你能发布你的布局吗?

标签: android android-fragments android-animation showcaseview


【解决方案1】:

我是这样解决的:

  1. 安装后只执行一次,我遵循this post
  2. 为了重复动画,我使用了this post 中提供的代码。

现在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;
        }
    

    【讨论】:

      【解决方案3】:

      按时间重复动画:

      sv.setRepeatCount(number);
      

      对于无限:

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

      在你的布局中:

      android:repeatMode="reverse"
      

      【讨论】:

      • 我在原帖中添加了布局。如果我尝试添加行 sv.setRepeatCount(Animation.INFINITE); 它会显示 setRepeatCount() is undefined for the type ShowCase View
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 1970-01-01
      • 2022-07-06
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      相关资源
      最近更新 更多