0

伙计们,我制作了一个自定义列表视图,列表视图有三个文本字段。我希望以下事情起作用,当用户从他刚刚填充文本视图的活动中按下后退按钮时,他会返回到包含自定义列表视图的活动。刚刚创建的最近条目已经存在于那里。每次用户进入列表视图活动时,我希望条目从右侧滑入。这是列表视图 xml 的代码:


    <LinearLayout
    android:id="@+id/listHolder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="#ffffff" >

    <ListView
        android:id="@+id/mylist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>
    </LinearLayout>

这里的列表视图实际上并没有利用完整的空间,因为 100dp 的屏幕尺寸被其他一些小部件占用(但这在这里并不重要)。我正在使用的动画是这样的:


    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <scale
    android:duration="1500"
    android:fillAfter="false"
    android:fromXScale="480dp"
    android:fromYScale="0dp"
    android:interpolator="@android:anim/overshoot_interpolator"
    android:pivotX="60"
    android:pivotY="10"
    android:toXScale="100dp"
    android:toYScale="0dp" />

    </set>

动画 xml 有什么问题?我是否为 x 和 y 值设置了错误的参数?我得到的是列表视图在用户进入该活动一秒钟或更晚之后出现。我的意思是没有从右到左的过渡。知道为什么会这样。谢谢。

4

1 回答 1

1

你甚至还没有将你的动画应用到列表视图,那么你怎么能显示动画!] 你应该%输入pivotYpivotX 使用这个代码:

将此另存为layout_controller.xml文件anim夹。

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
 android:animation="@anim/rotation"
 android:animationOrder="normal"
 android:delay="10%" />

anim在文件夹中将其另存为rotation.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromDegrees="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />

现在将此代码放入您的 listView 布局文件中:

<LinearLayout
android:id="@+id/listHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#ffffff" >

<ListView
    android:id="@+id/mylist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layoutAnimation="@anim/list_layout_controller" >
</ListView>
</LinearLayout>

我的意思是我已经在你的布局中添加了这一行,现在你可以看到它有效..

android:layoutAnimation="@anim/list_layout_controller" 
于 2012-10-12T12:10:01.397 回答