簡體   English   中英

Android RelativeLayout動畫問題

[英]Android RelativeLayout Animation issue

我基本上是在嘗試使用滑動動畫從屏幕底部(用戶看不見)到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);

            }
        });
    }

好消息:有效。

壞消息:不是我想要的。

此代碼使Layout滑入父布局的TOP中,而不遵循該布局的'alignParentBottom = true'屬性。 我希望它從任何地方滑入並停在父級底部

我應該做些什么改變?

如果您想從底部滑入,則可以使用簡單的android內置動畫,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM