我正在尝试在我的应用程序中为一个简单的 ImageView 设置动画,我希望它从屏幕底部滑入并到达 View 顶部 50px 离开屏幕顶部的静止位置(例如ImageView 的最终位置应为 X 中的 -50px)。我尝试使用 AbsoluteLayout 来执行此操作,但这实际上切断了 ImageView 的顶部 50px,因此顶部 50px 永远不会呈现。我需要让 ImageView 的顶部 50px 在动画时可见/渲染,然后让它稍微离开屏幕。我希望我已经解释得足够好。
这是我目前用作布局和滑入动画的内容(目前不渲染 ImageView 的顶部 50px):
布局:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/QuickPlayClipLayout">
<ImageView android:id="@+id/Clip"
android:background="@drawable/clip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_y="-50dp">
</ImageView>
</AbsoluteLayout>
动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="1000"/>
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000" />
</set>
提前致谢。
最佳答案
相反,我们可以简单地给 layout_margin(Top/left/right/bottom) 负值 例如:如果您希望您的 View 远离屏幕顶部,您可以指定
android:layout_marginTop="-40dp"
关于Android -- 如何将 View 定位到屏幕外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2554871/