0

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

我在这里尝试过这种方法,但是当我加载 ListView 并出现错误“java.lang.RuntimeException:未知动画名称:动画师”时,我的应用程序崩溃了

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

班级:

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();
}

}

动画 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>
4

1 回答 1

0

问题是alpha动画元素不是元素的一部分animator,是元素的一部分animation,要将动画器加载res到 android 代码中,您必须使用Animator类,而对于res动画,您必须使用Animation类。欲了解更多信息,请参阅Android Animation resources

于 2013-11-05T13:02:05.183 回答