Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 动画当用户单击按钮时,将按钮滑动到屏幕顶部_Java_Android_Android Layout_Android Animation_Android Button - Fatal编程技术网

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可见性之外,我还想通过一个简单的滑动动画(全部在屏幕上)将按钮的位置更改为三种设置之一,根据按下的按钮:

  • 按下TopButton-(打开活动,设置为现在)此按钮的滚动视图可见,其他两个按钮设置为Goe,两个按钮都位于屏幕底部

  • 按下中间按钮-滚动视图1和3将被设置为消失,滚动视图2将可见,
    中间按钮
    将在
    顶部按钮
    下方向上滑动。因此顺序将是
    顶部按钮
    中间按钮
    滚动/文本视图2
    底部按钮

  • 按下底部按钮-滚动视图1和2将被设置为消失,3将被设置为可见,
    底部按钮
    将向上滑动,以显示滚动视图的最大空间。因此,此滚动视图的顺序将是
    顶部按钮
    中间按钮
    底部按钮
    滚动/文本视图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%" />