【发布时间】:2014-08-08 09:06:40
【问题描述】:
我有一个布局,其中包含以相对布局排列的多个视图。此布局将在列表视图的适配器内膨胀。
现在我想分别为列表视图的每个元素设置动画(不是元素本身,而是其中的一个文本视图),例如在 onClick 事件上。动画应该包含一个文本视图的过渡和另一个文本视图的淡入淡出。
我真的不知道这里。我有我的 ArrayList of Objects,它保存了我的列表视图元素的数据。这个 ArrayList 被提供给填充文本视图的适配器。
我想我现在需要一种方法来处理文本视图。但是我该怎么做呢?我摆弄了 Adapter 类的 getView 方法,但没有任何成功。在适配器/数组列表中获取被点击元素的位置完全没有问题。 有什么想法/不同的方法吗?
我尝试在我的适配器中附加一个 ObjectAnimator,如下所示:
ObjectAnimator animation = ObjectAnimator.ofFloat(holder.txtPlayerPoints,"x", 200);
animation.setDuration(2000);
holder.txtPlayerPoints.setTag(R.id.tag_animation_in,animation);
在我的 onClick 中,我尝试像这样启动它:
((ObjectAnimator ) textView.getTag(R.id.tag_animation_in)).start();
对 textView 的引用是正确的,但它没有移动。调试器还说我的 textView 的“mTag”属性是“null”。有什么建议吗?
编辑:这是每个元素的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/bar_upper_height"
android:paddingLeft="@dimen/bar_name_padding"
android:text="Hendrik"
android:textSize="@dimen/font_player_name"
android:id="@+id/txtNamePlayer"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/txt_default"
android:textStyle="bold"
android:textColor="@android:color/white"
android:gravity="center_vertical" />
<TextView
android:layout_width="@dimen/bar_rank_width"
android:layout_height="@dimen/bar_rank_height"
android:layout_marginLeft="@dimen/bar_upper_margin"
android:layout_marginBottom="@dimen/bar_upper_margin"
android:textSize="@dimen/font_bar_info"
android:text="1"
android:id="@+id/txtRankPlayer"
android:layout_alignLeft="@id/txtNamePlayer"
android:layout_alignBottom="@id/txtNamePlayer"
android:background="@android:color/white"
android:textStyle="bold"
android:textColor="@color/txt_default"
android:gravity="center_vertical|center_horizontal" />
<ImageView
android:layout_width="@dimen/bar_arrow_width"
android:layout_height="@dimen/bar_rank_height"
android:id="@+id/imgActivePlayer"
android:layout_toRightOf="@id/txtRankPlayer"
android:layout_marginLeft="@dimen/bar_upper_margin"
android:layout_alignBottom="@id/txtNamePlayer"
android:layout_marginBottom="@dimen/bar_upper_margin"
android:background="@drawable/active_player" />
<TextView
android:layout_width="@dimen/bar_rank_height"
android:layout_height="@dimen/bar_rank_height"
android:layout_marginRight="@dimen/bar_upper_margin"
android:layout_marginBottom="@dimen/bar_upper_margin"
android:text="12"
android:id="@+id/txtPointsPlayer"
android:layout_alignRight="@id/txtNamePlayer"
android:layout_alignBottom="@id/txtNamePlayer"
android:background="@android:color/white"
android:textStyle="bold"
android:textColor="@color/txt_default"
android:textSize="@dimen/font_bar_info"
android:gravity="center_vertical|center_horizontal" />
<TextView
android:layout_width="@dimen/bar_rank_height"
android:layout_height="@dimen/bar_rank_height"
android:layout_marginRight="@dimen/bar_upper_margin"
android:layout_marginBottom="@dimen/bar_upper_margin"
android:layout_toLeftOf="@id/txtPointsPlayer"
android:layout_alignBottom="@id/txtNamePlayer"
android:text="0"
android:id="@+id/txtCurrScorePlayer"
android:background="@color/txt_disabled"
android:textColor="@android:color/white"
android:textSize="@dimen/font_bar_info"
android:gravity="center_vertical|center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:id="@+id/aheadBehindPlayer"
android:layout_width="fill_parent"
android:layout_height="@dimen/bar_lower_height"
android:layout_below="@+id/txtNamePlayer"
android:layout_centerHorizontal="true"
android:background="@color/txt_disabled"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ahead"
android:textSize="@dimen/font_bar_info"
android:textColor="@android:color/white"
android:id="@+id/textView2"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textSize="@dimen/font_bar_info"
android:textColor="@android:color/white"
android:id="@+id/txtPlayerAhead"
android:layout_weight="5"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textColor="@android:color/white"
android:textSize="@dimen/font_bar_info"
android:id="@+id/txtPlayerBehind"
android:textStyle="bold"
android:gravity="right"
android:layout_weight="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/behind"
android:textColor="@android:color/white"
android:textSize="@dimen/font_bar_info"
android:id="@+id/textView5"
android:gravity="right"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
我想为 txtPointsPLayer 和 txtCurrScorePlayer 制作动画。
【问题讨论】:
-
@mazen..你能给我们一些代码,以便我们研究它..这对你也有帮助..webdefllo.com/android-listview-with-animation.php
标签: android listview animation