开发者

Keep view above animation of another view

开发者 https://www.devze.com 2023-03-26 06:33 出处:网络
I have an Activity with a main screen that simply has a title bar (among other things).I have another TextView below the title bar that I have animate from top to bottom into place (it starts out as V

I have an Activity with a main screen that simply has a title bar (among other things). I have another TextView below the title bar that I have animate from top to bottom into place (it starts out as View.GONE, then I animate it visible and into place after an event from the user).

This works fine and dandy, except the TextView below the title bar animates above the title bar into place. I want it to seem as if the TextView came from undernea开发者_Go百科th the title bar. Both views are in a LinearLayout, so I'm not able to address the z-order like I would in a FrameLayout. Any suggestions?


I eventually solved this by encompassing the textview inside of a LinearLayout, then setting a LayoutAnimationController to the LinearLayout. This causes all the childs to be animated with respect to the parent container, which made the drop-down only to be rendered within the LinearLayout (which worked perfectly). Here is the code I used for the Animation Controller and ListView:

private void addDeleteDropAnimation() {
    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(150);
    set.addAnimation(animation);

    animation = new TranslateAnimation(
        Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
        Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
    );
    animation.setDuration(300);
    set.addAnimation(animation);

    controllerDel = new LayoutAnimationController(set, 0.5f);
    vw_delLinearLayout.setLayoutAnimation(controllerDel);
}


Handler handler = new Handler();
new Thread(){
    public void run(){
        TextView tv = (TextView)findViewById(R.id.xx);
        LayoutParams params = (LayoutParams)tv.getLayoutParams();
        handler.post(new Runnable(){
            public void run(){            
                tv.setVisible(View.Visible);
            }
        }
        int height = params.height;
        for(int i = 0; i < height + 1; i++) {
            params.topMargin = i - height;
            handler.post(new Runnable(){
                public void run(){            
                   tv.requestLayout();
                }
            }

            try{
                Thread.sleep(5);
            }catch(InterruptedException e){
            }
        }

    }
}.start();

you can try this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号