[英]Animation slide a Button to the top of the screen when The User Clicks a Button
我有一個具有三個按鈕,1在頂部(錨定相對布局TopButton
),一個在底部( BottomButton
,和一個將被直接置於下面的頂部按鈕或高於底部按鈕( MiddleButton
根據用戶觸摸)我的紐扣。
在這些按鈕的每個下方,我放置了一個ScrollView,然后在其中放置了textView。 我正在嘗試建立一組偵聽器,以便當用戶單擊一個按鈕時,其他兩個按鈕ScrollViews(及其View.GONE
)設置為View.GONE
,而按下的按鈕會將其ScrollView設置為View.Visible
。
除了設置ScrollViews可見性之外,我還想通過一個簡單的滑動動畫(全部顯示在屏幕上)將按鈕的位置更改為根據所按按鈕的三個設置之一:
按下TopButton- (打開“活動”,將其設置為現在)此按鈕的scrollView可見,另兩個按鈕都設置為“消失”,並且兩個按鈕均位於屏幕底部。
按下MiddleButton -ScrollView 1和ScrollView 3將被設置為不可用,並且ScrollView 2將可見,並且MiddleButton
將在TopButton
下方向上滑動。 因此順序將是TopButton
, MiddleButton
, Scroll/TextView2
, BottomButton
。
按下BottomButton-將 ScrollViews 1和2設置為Gone,將3設置為Visible,並且BottomButton
將向上滑動以顯示ScrollView的最大空間。 因此,此命令的順序為TopButton
, MiddleButton
, BottomButton
, Scroll/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>
我需要幫助找出fromY
和toY
值才能使此移動動畫正常工作。 這些要做什么?
這是我使用的翻譯動畫。 它稱為“ 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%" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.