【问题标题】:Android animate elements to top left and top rightAndroid动画元素到左上角和右上角
【发布时间】:2014-03-03 01:13:23
【问题描述】:

这是我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
        >
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:id="@+id/lin1"
            >
        <TextView
                android:layout_width="wrap_content"
                android:textSize="40sp"
                android:text="Score:0"
                android:id="@+id/textView"
                android:layout_height="wrap_content"
                android:layout_marginRight="10sp"/>
        <Chronometer
                android:id="@+id/chronometer"
                android:format="%s"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="40sp"
                android:layout_marginLeft="10sp"
                />
    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:gravity="center"
                  android:layout_below="@+id/lin1"
            >
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start Quiz Now"
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_centerHorizontal="true"
                android:id="@+id/startQuizButton"
                />
    </LinearLayout>

    <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/frameLayout"></FrameLayout>

</RelativeLayout>

这就是它的样子:

所以在点击按钮时,我希望分数文本框移动到屏幕的左上角,而计时器移动到屏幕的右上角。另外,该按钮将消失,并在framelayout 中出现一个包含测验问题的片段。

我已经为乐谱文本框尝试了以下动画,但它不再向左移动。:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
            android:fromXDelta="100%"
            android:toXDelta="0%p"
            android:duration="900"
            >
    </translate>
     
</set>

另外,即使我让一些动画工作,盒子也会在动画结束后恢复到初始大小。我希望它留在那里。 我已经对这些价值观进行了很多尝试,但无法让它发挥作用。请帮忙。

【问题讨论】:

    标签: android android-layout user-interface


    【解决方案1】:

    尝试将 toX 值更改为“0dp”并添加一个 fillAfter ="true"。查看http://developer.android.com/reference/android/view/animation/Animation.html 获取更多关于动画的帮助

    【讨论】:

    • Android 资源打包:[fq] /Users/rajat.khandelwal/fq/res/Android 资源打包:[fq] /Users/rajat.khandelwal/fq/res/anim/move_to_top_left.xml: 4:错误:错误:不允许维度类型(在“toXDelta”处,值为“0dp”).anim/move_to_top_left.xml:4:错误:错误:不允许维度类型(在“toXDelta”处,值为“0dp”)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 2013-05-10
    相关资源
    最近更新 更多