android - 将 View 动画转换到屏幕边缘

标签 android android-animation

我试图从它的位置到屏幕边缘对 View 进行动画处理,100%p 将 View 移出屏幕,

required animation

图像描述了所需的动画,对于任何要求代码的人:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fillAfter="true" >

    <translate
        android:fromXDelta="0%"
        android:toXDelta="100%" />

</set>

任何帮助将不胜感激

最佳答案

来自 android doc :

android:toXDelta

Float or percentage. Ending X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").

假设您的按钮宽度是其父级宽度的 20%,您必须将 toXDelta 指定为

50%p-(20%p/2) = 40%p

此解决方案的问题是您可能不知道按钮宽度的“父级宽度的百分比”(不确定,因为您没有发布 xml)。所以我建议以编程方式定义动画。

关于android - 将 View 动画转换到屏幕边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14090700/

相关文章:

android - 将按钮添加到 ExpandableListView 组项

java - Android OpenGL ES 2.0 : Cube model is not only distorted (perspective is wrong?),但面部加载不正确(顶点不正确?)

Android:从正在运行的服务中获取实例

java - 如何使用transition改变android studio中圆形按钮的颜色

android - 带有两个 RecyclerView 的 CoordinatorLayout

Android - 使用自定义字体

Android圆圈弹跳动画

android - 在 Horizo​​ntal RecyclerView 上相对于中心设置 Item Alpha

java - 无法在分离 View 上启动此动画师!显露效果

java - 动画 hasStarted() 或 hasEnded() 不起作用