【问题标题】:Move layout elements using animation使用动画移动布局元素
【发布时间】:2017-12-18 20:32:20
【问题描述】:

现在我有一个这样的简单布局:

-----------------------------------
   button1       |       button2  
-----------------------------------
 Welcome to my App.

当用户点击button1时,我想从右侧显示一个侧边栏(平滑滑动),并将两个按钮平滑移动到左侧:

-----------------------------------
button1|button2|      Side bar    
---------------|
Welcome        |
to my App.     |    some text that
               |    shows some infos

当我再次单击 button1 时,侧边栏应该会消失(向右滑动),我们的布局与第一个相同。

现在我有两个问题:

  1. 我想要的侧边栏并不是真正的导航栏,所以我不想在Android 中使用sidebar。还有其他更适合我使用的替代品吗?

  2. 我怎样才能做到这一点,当侧边栏从右侧出现时,将所有内容(包括两个按钮和文本)向左移动以便为侧边栏留出空间?有没有办法正确地做到这一点?

【问题讨论】:

标签: android android-layout user-interface


【解决方案1】:

你可以像这样使用 TranslateAnimation

TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 150);  //use Sidebar.length() to move according to sidebar                          
                            anim.setDuration(1000);
                            anim.setFillAfter(true);
                            animWindow.setDuration(1000);
                            animWindow.setFillAfter(true);
                            button1.setAnimation(anim);
                            button2.setAnimation(anim);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多