views:

40

answers:

1

I have a ListView that can have one or more clickable items. When I apply a rotate animation the coordinates that are clicked correspond to the original position of the ListView items. For example a list with one item in portrait mode rotated 180 degrees will have the item upside down on the bottom of the screen, but the item gets the click event when I click the top of the screen. 180 degrees is just an example I want to be able to move an arbitrary angle. I've looked through all the listView properties but none seem to have any effect on the clickable coordinates. I would assume willChangeTransformationMatrix would do the trick but it doesn't, neither does invalidate or invalidateViews. Is there a property I'm overlooking or how would I go about moving the coordinates to the right place?

Thanks

sample code- list items highlight correctly when clicked, rotate with dpad_center, after rotated items highlight when original position is clicked. I've tried animating the animation, animationSet, and layoutAnimationController all same result.

public class ToDoList extends Activity { ListView myListView; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ListView myListView = new ListView(this);

final ArrayList<String> todoItems = new ArrayList<String>();
todoItems.add(0, "asdf");
todoItems.add(0, "1234");

// Create the array adapter to bind the array to the listview
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems);

// Bind the array adapter to the listview.
myListView.setAdapter(aa);
setContentView(myListView);
myListView.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
      if (event.getAction() == KeyEvent.ACTION_DOWN)
        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
        {
          aa.notifyDataSetChanged();
          //myEditText.setText("");
          RotateAnimation  ranim = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
          ranim.setDuration(1000);  
          ranim.setFillAfter(true);
          ranim.willChangeBounds();
          ranim.willChangeTransformationMatrix();
          ranim.setInterpolator(new LinearInterpolator());
          myListView.startAnimation(ranim);
          AnimationSet set = new AnimationSet(true);
          set.addAnimation(ranim);
          set.willChangeTransformationMatrix();
          set.setInterpolator(new LinearInterpolator());
          //set.setFillAfter(true);
          //set.setFillEnabled(true);
          LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
          controller.setInterpolator(new LinearInterpolator());
          myListView.setLayoutAnimation(controller);
          return true;
        }
      return false;
    }
  });

} }

+1  A: 

You are getting the correct coordinates. RotateAnimation affects only the rendering of a View, not its layout or touch events.

Romain Guy
I guess when I asked "how would I go about moving the coordinates to the right place?" by "right" I meant the newly rotated place where pretty much any person would expect them to be (under the item that is actually clicked). Any idea?Thanks
JA1
@JA1: Step #1 is for you to determine how to have a sideways `ListView`, without any animations. If you cannot do it without an animation, you cannot do it with an animation, either. Since I am not aware of a way you can have a sideways `ListView`, I suspect that you will need to revise your UI plans.
CommonsWare
This is pretty disappointing, I had looked at other ways of rotating w/out animation but only found how to do it to ImageViews. I also just tried animating an imageView, moving across screen onTouch, and the coordinates don't follow it either, you have to re-touch the original position to re-animate. This seems like a huge limitation, but I still think I'm overlooking something simple or there could be some way to adjust the coordinates. I mean a ListView with >10 items that is scrolled through does do some adjustments for position when items scroll out of view, similar to animation
JA1