java-旋转图像的位置

时间:2014-07-05 12:52:01

标签: java android graphics

我有一个listView,每行都有一个图标。

我希望当我点击该行时,图像开始在其自身的中心旋转,就像进度条一样。

我正在搜索,但我真的对java中的图形一无所知,这就是我所需要的一切!!

谢谢

1 个答案:

答案 0 :(得分:1)

假设你像这样定义一个xml文件list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ImageView 
       android:id="@+id/image_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"/>
</LinearLayout>

您可以使用具有不同属性的RotateAnimation来获得所需的样式。

listview.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View view, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
        ImageView imageView = (ImageView) view.findViewById(R.id.image_view);
        Animation rotateAnimation = new       
        RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 
        rotateAnimation.setInterpolator(new LinearInterpolator());
        rotateAnimation.setRepeatCount(3);
        rotateAnimation.setDuration(3000);              
        imageView.startAnimation(rotateAnimation);        
    }
});
相关问题