将片段部分移出屏幕 [英] Moving a fragment partially off screen

查看:67
本文介绍了将片段部分移出屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此困扰了很长时间了.我试图将包含在FrameLayout中的片段向右移动,以使仅片段的左20%可见.

i have been stumped on this for quite a while now. I am trying to move my fragment which is contained in a FrameLayout, to the right, so that only the left 20% of the fragment is visible.

我认为我遇到的问题是,父对象不会让片段移动到其边界之外,或者我不知道如何移动它.我尝试过的所有操作都只是将片段推向右墙,然后将片段缩放到适合的大小.我需要它将碎片推到右墙外面.任何帮助将不胜感激.

The problem I think I am running into is that the parent won't let the fragment move outside its bounds, or I do not know how to move it. Everything I have tried has just shoved the fragment up against the right wall, and scaling the fragment to fit. I need it to push the fragment outside the right wall. Any help would be more than appreciated.

我想要达到的最终效果是,当您按下一个推入式片段时,该片段会转换为完整视图,然后按一下按钮就可以转换回20%的视图.我已经设置好动画,只是片段的实际移动使我难堪.

The final effect I am trying to achieve, is that when you push a put-on the fragment translates into full view, and then with the push of a button translates back to 20% view. i have the animation all set up, just the actual moving of the fragment is stumping me.

推荐答案

这意味着尽管可以动画,但这并不意味着片段本身就是动画使它看起来像的位置.在实际移动之前,它仍将在原始位置接收OnClick事件.

It means that although it animates, that does not mean the fragment itself is where the animation makes it appear to be. It will still receive OnClick events at the original position until it is physically moved.

您可能正在使用老式动画(例如TranslateAnimation),这些动画是为瞬时效果而不是永久效果而设计的.

You are probably using old-style animations (e.g., TranslateAnimation), which were designed for transient effects, not permanent ones.

我向您指出相关问题的原因我的是许多解决方案,包括我自己的解决方案都使用了新的动画器框架,该框架旨在效果更持久.

The reason I pointed you to a related question of mine was that many of the solutions, including my own solution use the new animator framework, which is designed for longer-lasting effects.

同样,该示例也无济于事,我试图将其部分移出屏幕,而不仅仅是将其紧缩在边缘.

Also that example does not help me, I am trying to move it partially off screen, not just scrunch it up against an edge.

特别是对于动画制作器框架,将其部分移出屏幕"和将其向上边缘修剪"之间没有实质性区别.例如,如果您已经阅读了我的解决方案,您将看到一个translateWidgets()方法,该方法演示了一组小部件的水平滑动:

Particularly with respect to the animator framework, there is no material difference between "move it partially off screen" and "scrunch it up against an edge". For example, if you had read my solution, you would have seen a translateWidgets() method demonstrating a horizontal slide of a set of widgets:

private void translateWidgets(int deltaX, View... views) {
    for (final View v : views) {
      v.setLayerType(View.LAYER_TYPE_HARDWARE, null);

      v.animate().translationXBy(deltaX).setDuration(ANIM_DURATION)
       .setListener(new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           v.setLayerType(View.LAYER_TYPE_NONE, null);
         }
       });
    }
  }

在您的情况下,deltaX将是达到20%效果(可能是0.2f乘以容器宽度或沿这些方向的值)的适当值,或者是当完整片段应消除该效果时的任何合适值.被看到.

In your case, deltaX would be whatever the appropriate value is to achieve your 20% effect (presumably 0.2f times the container's width, or something along those lines), or to undo that effect when the full fragment should be seen.

我的答案包含指向完整示例项目的链接,这些链接既适用于本机API Level 11动画师,又使用动画师框架的NineOldAndroids反向端口.

My answer contains links to full sample projects, both for the native API Level 11 animators, and using the NineOldAndroids backport of the animator framework.

这篇关于将片段部分移出屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆