【问题标题】:Animation slide a Button to the top of the screen when The User Clicks a Button当用户单击按钮时,动画将按钮滑到屏幕顶部
【发布时间】:2014-09-27 03:49:20
【问题描述】:

我的相对布局具有三个按钮,1 个锚定在顶部(TopButton),一个在底部(BottomButton,一个将直接放置在顶部按钮下方或底部按钮上方( MiddleButton) 根据用户触摸我的按钮。

在每个按钮下,我放置了一个 ScrollView,然后在其中放置了一个 textView。我正在尝试创建一组侦听器,以便当用户单击其中一个按钮时,其他两个按钮 ScrollViews(及其 textViews)设置为View.GONE,并且按下的按钮将其 ScrollView 设置为View.Visible

除了设置 ScrollViews 可见性之外,我还想根据按下的按钮通过简单的滑动动画(全部在屏幕上)将按钮的位置更改为三种设置之一:

  1. TopButton pushed - (打开Activity,现在设置什么)这个按钮的scrollView是可见的,另外两个设置为gone,两个按钮都在底部屏幕。

  2. MiddleButton push - ScrollView 1 和 3 将设置为消失,ScrollView 2 将可见,MiddleButton 将在 TopButton 下方向上滑动。所以顺序将是TopButtonMiddleButtonScroll/TextView2BottomButton

  3. BottomButton pushed - ScrollViews 1 和 2 将设置为 Gone,3 将设置为 Visible,BottomButton 将向上滑动以显示 ScrollView 的最大空间。所以这个顺序是TopButtonMiddleButtonBottomButtonScroll/TextView3

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/OverallLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    tools:context="${relativePackage}.${activityClass}" >
    
    <Button
    android:id="@+id/TopButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" />
    
    <Button
    android:id="@+id/BottomButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />
    
    <Button
    android:id="@+id/MiddleButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/BottomButton" />
    
    <ScrollView
    android:id="@+id/Scroll1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/MiddleButton"
    android:layout_below="@id/TopButton"
    android:visibility="visible" >
    
    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center" />
    </ScrollView>
    
    <ScrollView
    android:id="@+id/Scroll2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/BottomButton"
    android:layout_below="@id/MiddleButton"
    android:visibility="gone" >
    
    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center" />
     </ScrollView>
    
    <ScrollView
    android:id="@+id/Scroll3"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/BottomButton"
    android:visibility="gone" >
    
    <TextView
        android:id="@+id/textView3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center" />
    </ScrollView>
    
    </RelativeLayout>
    

我需要帮助确定 fromYtoY 值才能使这个移动动画正常工作。这些设置是什么?

【问题讨论】:

  • 您有什么具体问题吗?
  • 我将如何制作这些动画?我从这个开始:&lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;translate android:fromXDelta="0" android:fromYDelta="-1000" android:duration="1500"/&gt; &lt;/set&gt; 但它会将按钮冲到顶部,然后慢慢将其拖到开始的位置。

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


【解决方案1】:

这是我使用的翻译动画。它叫做“pull_in_from_top.xml”

<?xml version="1.0" encoding="utf-8"?>
 <translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromYDelta="-100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toYDelta="0%" />

这个做相反的“push_out_to_top.xml”

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromYDelta="0%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toYDelta="-100%" />

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多