【问题标题】:Android: specify circular reveal animation starting position?Android:指定圆形显示动画的起始位置?
【发布时间】:2017-01-28 11:59:41
【问题描述】:

我目前有一个从工具栏最右侧开始的圆形显示动画。我希望最初的圆心从“搜索”图标开始,这让我很难找到答案。我尝试更改 cxxy 值但没有成功。任何帮助表示赞赏。

final Toolbar search_bar = (Toolbar) findViewById(R.id.search_toolbar);

                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    int cx = search_bar.getWidth();
                    int cy = search_bar.getHeight()/2;

                    float finalRadius = (float) Math.hypot(cx, cy);

                    Animator anim =
                            ViewAnimationUtils.createCircularReveal(search_bar, cx, cy, 0, finalRadius);

                    search_bar.setVisibility(View.VISIBLE);
                    anim.start();
                }

【问题讨论】:

    标签: java android android-animation circularreveal


    【解决方案1】:

    试试这个:

    public void startCircularReveal() {
        final View view = findViewById(R.id.linearLayout);
        final View startView = findViewById(R.id.button_container);
        int cx = (startView.getLeft() + startView.getRight()) / 2;
        int cy = (startView.getTop() + startView.getBottom()) / 2;
        view.setBackgroundColor(Color.parseColor("#6FA6FF"));
        int finalRadius = Math.max(cy , view.getHeight() - cy);
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
    
            }
    
            @Override
            public void onAnimationEnd(Animator animation) {
    
            }
    
            @Override
            public void onAnimationCancel(Animator animation) {
    
            }
    
            @Override
            public void onAnimationRepeat(Animator animation) {
    
            }
        });
        anim.setDuration(200);
        view.setVisibility(View.VISIBLE);
        anim.start();
    }
    

    将视图更改为您想要在其顶部显示的视图(通常是根视图),并将 startView 更改为您的“搜索”图标视图,onAnimationEnd 在显示完成后执行您想要的任何操作。

    更新

    如果显示不在您的视图顶部,则可以通过将此视图添加到布局底部来修复它

                <LinearLayout
                    android:id="@+id/linearLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/custom_theme_color"
                    android:orientation="vertical"
                    android:visibility="invisible">
                </LinearLayout>
    

    确保视图“视图”设置为该布局的 id

    final View view = findViewById(R.id.linearLayout);
    

    基本上,我所做的是添加一个 LinearLayout 并将其宽度和高度设置为匹配 match_parent,因此该视图位于所有内容之上,该视图是显示将位于顶部的位置,并确保该视图不t 影响您的布局我将可见性设置为不可见,并在显示开始时将其设置为可见:

    view.setVisibility(View.VISIBLE);

    希望对你有帮助。

    【讨论】:

    • 非常感谢,这是非常有用的。但是,动画现在直接从搜索图标的另一侧开始,这很奇怪。
    • 你说的“反面”是什么意思,你能解释一下吗?
    • 剪裁圈现在从图片中“标题”区域附近开始,而不是在“图标”顶部。我觉得这很奇怪,你的回答是合乎逻辑的。
    • 我知道为什么会这样,一会儿我会更新答案。
    • 感谢您的帮助。
    【解决方案2】:
    revealView(listview, RssFragment.this.ll);
    
    public  void revealView(View toBeRevealed, View frame)
    {
        if (!ViewCompat.isAttachedToWindow(toBeRevealed))
        {
            return;
        }
        if (VERSION.SDK_INT >= 21)
        {
            Animator anim = ViewAnimationUtils.createCircularReveal(toBeRevealed, (frame.getLeft() + frame.getRight()) / 2, (frame.getTop() + frame.getBottom()) / 2, 0.0f, (float) Math.max(frame.getWidth(), frame.getHeight()));
            toBeRevealed.setVisibility(View.VISIBLE);
            anim.start();
            return;
        }
        toBeRevealed.setVisibility(View.VISIBLE);
    }
    

    【讨论】:

      【解决方案3】:

      你可以试试这个:

      enter i
      nt cx = search_bar.getRight() * 5 / 6;
      int cy = (search_bar.getTop() + search_bar.getBottom()) / 2;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-19
        相关资源
        最近更新 更多