Android的 - 动画视图的TOPMARGIN / bottomMargin的/ etc中的LinearLayout或RelativeLayout的 [英] Android - Animate a View's topMargin/bottomMargin/etc in LinearLayout or RelativeLayout

查看:296
本文介绍了Android的 - 动画视图的TOPMARGIN / bottomMargin的/ etc中的LinearLayout或RelativeLayout的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个从底部向上滑动菜单。它从菜单中的观点只是看到在屏幕的底部,然后单击它使其向上滑动。我试着用 TranslateAnimation ,但虽然像素移动,菜单的灾区都在相同的位置和以前一样。所以我想,如果我可以调整菜单的利润后,动画完成,这将完成我想要的。但是,我不知道如何来调整页边距。

I am trying to create a menu that slides up from the bottom. It starts with the menu's view just visible at the bottom of the screen, and then clicking it causes it to slide up. I tried using a TranslateAnimation, but although the pixels move, the hit areas of the menu are in the same position as before. So I think that if I can adjust the menu's margins after the animation is complete, this will accomplish what I want. However, I can't figure out how to adjust the margins.

我试图创建一个 LinearLayout.LayoutMargins 对象,然后设置其利润率,并将其应用到菜单的观点(这是一个的LinearLayout ),但是这是行不通的。

I've tried to create a LinearLayout.LayoutMargins object and then set its margins and apply it to the menu's view (which is a LinearLayout), but this doesn't work.

任何想法?

推荐答案

我的解决方案是创建两个LinearLayouts,一个是它的状态(设置为走了),另一个在菜单的下跌状态。然后,当用户点击按钮,滑动菜单,我称之为 TranslateAnimation 显示菜单向上滑动。我把一个监听器上,导致向上的状态可见动画和关闭状态在动画完成时消失。我扭转了这种对于收的动作。

My solution was to create two LinearLayouts, one in it's up state (set to gone) and the other in the menu's down state. Then when the user clicks on the button to slide the menu up, I call a TranslateAnimation showing the menu slide up. I put a listener on the animation that causes the up state to be visible and the down state to be gone when the animation finishes. I reversed this for the "closing" action.

不完全是我原来想象的这样做,但它的工作方式。

Not exactly the way I had originally imagined doing it, but it worked.

这篇关于Android的 - 动画视图的TOPMARGIN / bottomMargin的/ etc中的LinearLayout或RelativeLayout的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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