Android 为listView中的图像创建淡入动画

Android 为listView中的图像创建淡入动画,android,listview,android-animation,Android,Listview,Android Animation,我目前正在尝试在列表视图中设置图像,以便在加载图像时加载淡入动画 我尝试过这样做,但当我加载ListView时,我的应用程序崩溃,错误为“java.lang.RuntimeException:未知动画名称:animator” " 如果有人能给我一些关于在列表视图图像中淡出的指导,那就太好了 类别: public class Fragment2 extends ListFragment { public class MyListAdapter extends ArrayAdapter<St

我目前正在尝试在列表视图中设置图像,以便在加载图像时加载淡入动画

我尝试过这样做,但当我加载ListView时,我的应用程序崩溃,错误为“java.lang.RuntimeException:未知动画名称:animator” "

如果有人能给我一些关于在列表视图图像中淡出的指导,那就太好了

类别:

public class Fragment2 extends ListFragment {

public class MyListAdapter extends ArrayAdapter<String> {

    Context myContext;

    public MyListAdapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
        myContext = context;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // return super.getView(position, convertView, parent);

        LayoutInflater inflater = (LayoutInflater) myContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.row, parent, false);
        TextView label = (TextView) row.findViewById(R.id.month);
        label.setText(month[position]);
        ImageView icon = (ImageView) row.findViewById(R.id.icon);

        Animation fadeInAnimation = AnimationUtils.loadAnimation(getContext(), R.animator.animation);
        //Now Set your animation
        icon.startAnimation(fadeInAnimation );

        // Customize your icon here
        icon.setImageResource(drawables[position]);



        return row;
    }

}

int[] drawables = { R.drawable.transparent_picture, R.drawable.abstract_icon,
        R.drawable.animal_icon, R.drawable.anime_icon,
        R.drawable.artistic_icon, R.drawable.cartoon_icon,
        R.drawable.comic_icon, R.drawable.icon_celeberity,
        R.drawable.icon_cars, R.drawable.icon_fantasy,
        R.drawable.icon_food,

};

String[] month = { " ", "Abstract", "Animal", "Anime", "Artistic",
        "Cartoon", "Comics", "Celeberity", "Cars", "Fantasy", "Food" };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    MyListAdapter myListAdapter = new MyListAdapter(getActivity(),
            R.layout.row, month);
    setListAdapter(myListAdapter);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragments_layout2, container, false);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Toast.makeText(getActivity(),
            getListView().getItemAtPosition(position).toString(),
            Toast.LENGTH_LONG).show();
}

}
公共类Fragment2扩展了ListFragment{
公共类MyListAdapter扩展了ArrayAdapter{
语境;
公共MyListAdapter(上下文,int textViewResourceId,
字符串[]对象){
超级(上下文、textViewResourceId、对象);
myContext=上下文;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//返回super.getView(position、convertView、parent);
LayoutFlater充气器=(LayoutFlater)myContext
.getSystemService(上下文布局\充气机\服务);
视图行=充气机。充气(R.layout.row,父级,false);
TextView标签=(TextView)row.findViewById(R.id.month);
label.setText(月[职位]);
ImageView图标=(ImageView)row.findViewById(R.id.icon);
Animation fadeInAnimation=AnimationUtils.loadAnimation(getContext(),R.animator.Animation);
//现在设置动画
图标。startAnimation(fadeInAnimation);
//在此自定义您的图标
icon.setImageResource(可绘图[位置]);
返回行;
}
}
int[]drawables={R.drawable.transparent\u图片,R.drawable.abstract\u图标,
R.drawable.animal_图标,R.drawable.Animae_图标,
R.drawable.艺术图标,R.drawable.卡通图标,
R.drawable.comic_图标,R.drawable.icon_快捷,
R.drawable.icon_汽车,R.drawable.icon_幻想,
R.drawable.icon_食品,
};
字符串[]月={“,”抽象“,”动物“,”动画“,”艺术“,
“卡通”、“漫画”、“敏捷”、“汽车”、“幻想”、“食品”};
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
MyListAdapter MyListAdapter=新的MyListAdapter(getActivity(),
R.layout.row,月);
setListAdapter(myListAdapter);
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
返回充气机。充气(R.layout.fragments\U layout2,容器,假);
}
@凌驾
public void onListItemClick(列表视图l、视图v、整数位置、长id){
Toast.makeText(getActivity(),
getListView().getItemAtPosition(position).toString(),
Toast.LENGTH_LONG).show();
}
}
动画XML:

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

<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:duration="200"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:repeatCount="infinite"
        android:toAlpha="1.0" />
</set>

</animator>


问题是
alpha
动画元素不是
animator
的一部分,是
动画
元素的一部分,要将
res
动画加载到android代码中,必须使用
animator
类,对于
res
动画,必须使用
动画
类。有关更多信息,请参见

请显示动画设置代码检查更新的答案。