Clicking Rotated ListView gives wrong/original coordinates

Problems with Canvas, OpenGL, etc...

Clicking Rotated ListView gives wrong/original coordinates

Postby JA1 » Wed Aug 25, 2010 5:26 am

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 (clicking the item from the rotated position not the original)?

Alternatively is there a way to rotate the listView without animation and achieve the effect I'm expecting?


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.

Code: Select all

import java.util.ArrayList;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class ToDoList extends Activity {
   ListView myListView;
  /** Called when the activity is first created. */
  public void onCreate(Bundle 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.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
          if (event.getAction() == KeyEvent.ACTION_DOWN)
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
              RotateAnimation  ranim = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
             ranim.setInterpolator(new LinearInterpolator());
             AnimationSet set = new AnimationSet(true);
             set.setInterpolator(new LinearInterpolator());
             LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
              controller.setInterpolator(new LinearInterpolator());
              return true;
          return false;
Once Poster
Once Poster
Posts: 1
Joined: Wed Aug 25, 2010 5:19 am


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 4 guests