Java 动画当用户单击按钮时,将按钮滑动到屏幕顶部
我的相对布局有三个按钮,一个固定在顶部(Java 动画当用户单击按钮时,将按钮滑动到屏幕顶部,java,android,android-layout,android-animation,android-button,Java,Android,Android Layout,Android Animation,Android Button,我的相对布局有三个按钮,一个固定在顶部(TopButton),一个在底部(BottomButton),另一个将根据用户触摸我的按钮的情况直接放置在顶部按钮的下方或底部按钮的上方(MiddleButton) 在每个按钮下,我都放置了一个滚动视图,然后在其中放置了一个文本视图。我试图创建一组侦听器,以便当用户单击其中一个按钮时,其他两个按钮可以滚动视图(及其文本视图)设置为View.GONE,按下的按钮将其滚动视图设置为View.Visible 除了设置ScrollView可见性之外,我还想通过一个
TopButton
),一个在底部(BottomButton
),另一个将根据用户触摸我的按钮的情况直接放置在顶部按钮的下方或底部按钮的上方(MiddleButton
)
在每个按钮下,我都放置了一个滚动视图,然后在其中放置了一个文本视图。我试图创建一组侦听器,以便当用户单击其中一个按钮时,其他两个按钮可以滚动视图(及其文本视图)设置为View.GONE
,按下的按钮将其滚动视图设置为View.Visible
除了设置ScrollView可见性之外,我还想通过一个简单的滑动动画(全部在屏幕上)将按钮的位置更改为三种设置之一,根据按下的按钮:
中间按钮
将在顶部按钮
下方向上滑动。因此顺序将是顶部按钮
,中间按钮
,滚动/文本视图2
,底部按钮
底部按钮
将向上滑动,以显示滚动视图的最大空间。因此,此滚动视图的顺序将是顶部按钮
,中间按钮
,底部按钮
,滚动/文本视图3
>
<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>
我需要帮助计算出这个移动动画的
fromY
和toY
值。这些值设置为什么?这是我使用的一个翻译动画。它被称为“pull\u in\u from\u top.xml”
这个函数的作用正好相反,“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="-100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toYDelta="0%" />
<?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%" />