0

I programatically moved a layout with several child views. The child views all display in their new positions. However, the click and touch events are still working as if the views were in their old positions. What do I do?

Edit:

I used translate and scale to move the layout. Here is the code from a class extending LinearLayout:

@Override
protected void onDraw(Canvas canvas) {
    canvas.translate(getWidth(), 0);
    canvas.scale(-1, 1);
    super.onDraw(canvas);
}

I use this new layout in multiple activities, but the issue is the same for all of them. Here is one of the simpler layouts:

<?xml version="1.0" encoding="utf-8"?>
<com.example.myapp.NewLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/chapter_gridview"
        style="@style/GridStyle" />

</com.example.myapp.NewLayout>

Any solutions?

Update

One way may be to update the LayoutParams but I am not sure how to do that yet. These are some related questions I found:

OnClickListener issues after ImageButton moved after TranslateAnimation

How can I dynamically set the position of view in Android?

http://www.clingmarks.com/how-to-permanently-move-view-with-animation-effect-in-android/400

Edit

No solutions? I give up then.

Community
  • 1
  • 1
Suragch
  • 935
  • 3
  • 9
  • 15

1 Answers1

0

If you are working with AnimationTranslation : Your LinearLayout had been moved seemingly,but it's just visually moved.The LinearLayout is still where it is before the animation.

try this to your layout :

mylayout.layout(x,x,x,x);

I took my answer from here

you can also see this question

EDIT

If you are working with Canvas.translate :

try padding in place of translate : canvas.setPadding(getWidth(), 0);

Community
  • 1
  • 1
ahmed_khan_89
  • 2,755
  • 26
  • 49
  • I read the links you gave several times but I can't see how to implement your advice. Maybe it is because I'm not using animation. – Suragch May 08 '14 at 11:11
  • I tried `canvas.setPadding(getWidth(), 0);` but I got the error: The method setPadding(int, int) is undefined for the type Canvas – Suragch May 09 '14 at 04:08