【问题标题】:Android RelativeLayout Animation issueAndroid RelativeLayout 动画问题
【发布时间】:2015-11-25 13:39:02
【问题描述】:

我基本上是在尝试使用滑动动画从屏幕底部(用户视线之外)到 RelativeLayout 的原始位置(在 xml 编辑器中编码)为 RelativeLayout 设置动画。类似于从底部滑入的 iOS 上下文框。

这是我的 XML:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <TextView
            android:id="@+id/welcomemsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:text="Open Panel
            android:textSize="42sp" />

      <!-- The layout that slides in from nowhere -->
      <RelativeLayout
              android:id="@+id/bottomSpinner"
              android:layout_width="fill_parent"
              android:layout_height="250dp"
              android:layout_alignParentBottom="true"
              android:background="#ffffff"
              android:visibility="visible">

      </RelativeLayout>

</RelativeLayout>

我的代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_view);

        //Start the animation
        SlideToAbove();

}

//bottomSpinner is my Slide in Panel
public void SlideToAbove() {
        Animation slide = null;
        slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
                0.0f, Animation.RELATIVE_TO_SELF, -5.0f);

        slide.setDuration(400);
        slide.setFillAfter(true);
        slide.setFillEnabled(true);
        bottomSpinner.startAnimation(slide);

        slide.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {

                bottomSpinner.clearAnimation();

                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        bottomSpinner.getWidth(), bottomSpinner.getHeight());
                lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                bottomSpinner.setLayoutParams(lp);

            }
        });
    }

好消息:有效。

坏消息:不是我想要的。

此代码使布局滑入父布局的顶部,而不是遵守布局的 'alignParentBottom=true' 属性。我希望它从 nowhere 滑入并停在 父底部

我应该做些什么改变?

【问题讨论】:

    标签: java android android-layout android-animation android-relativelayout


    【解决方案1】:

    如果你想从底部滑入,你可以使用简单的 android 内置动画,如下所示:

    Animation animation = AnimationUtils.loadAnimation(this,R.anim.abc_slide_in_bottom);
    yourLayout.startAnimation(animation);
    

    【讨论】:

    • 只需将 anim 更改为 R.anim.abc_slide_out_bottom
    猜你喜欢
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2011-03-20
    • 1970-01-01
    相关资源
    最近更新 更多