3

I have two button in one LinearLayout and inside this LinearLayout i have two button. When i animate LinearLayout then working fine but when tried to click on Button which is inside LinearLayout, click of button is not working.

I already searched a lot but not able get rid this issue.

Below code to animate LinearLayout

an = new RotateAnimation(angleRightHead, getRotateAngleRightEdgehead (), Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0.33f);
an.setRepeatMode(Animation.REVERSE);
an.setDuration(1000);              
an.setRepeatCount(0);                
an.setFillAfter(true);   
an.setFillEnabled(true);   
head_neck_ll.startAnimation(an); 

and this code of XML

<LinearLayout  
    android:id="@+id/head_neck_idll"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:gravity="center"  
    android:orientation="horizontal" >    

    <Button
        android:id="@+id/head"
        android:layout_width="70dp"
        android:layout_height="20dp"
        android:background="@drawable/roundcorner"
        android:clickable="true"
        android:onClick="clickhander" />
     <!-- </RelativeLayout> -->

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:padding="3dp"
            android:layout_height="16dp" >

            <Button
                android:id="@+id/lumber"
                android:layout_width="49dp"
                android:layout_marginLeft="3dp"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerVertical="true"
                android:layout_marginBottom="-10dp"
                android:background="@drawable/roundcorner"
                android:clickable="true"
                android:onClick="clickhander" />

        </RelativeLayout>

        <Button
            android:id="@+id/backupper"
            android:layout_width="80dp"
            android:layout_height="20dp"
            android:background="@drawable/roundcorner"
            android:clickable="true"
            android:onClick="clickhander" />
    </LinearLayout>

</LinearLayout>

and code for onClickListener

public void clickhander(View v){
    if(v.getId() == R.id.head){
        textv = head;
        v1right = mapRight.get(head);
        v1right = mapLeft.get(head);

        head.setBackgroundResource(R.drawable.clickroundcorner);
        lumber.setBackgroundResource(R.drawable.roundcorner);
        backupper.setBackgroundResource(R.drawable.roundcorner);
        backlower.setBackgroundResource(R.drawable.roundcorner);    
        legside.setBackgroundResource(R.drawable.roundcorner);
        angle =0;
    } else if(v.getId() == R.id.backupper){
        textv = backupper;
        v1right = mapRight.get(backupper);
        v1right = mapLeft.get(backupper);

        backupper.setBackgroundResource(R.drawable.clickroundcorner);
        head.setBackgroundResource(R.drawable.roundcorner);   
        lumber.setBackgroundResource(R.drawable.roundcorner);
        backlower.setBackgroundResource(R.drawable.roundcorner);
        legside.setBackgroundResource(R.drawable.roundcorner);
        angle =0;
    }
}

Check the image:

Myrequirement

Note: 1 and 2 both are in same layout. I want click listener on each with layout animation

Your help would be appreciated.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Subhalaxmi
  • 5,687
  • 3
  • 26
  • 42

1 Answers1

-2

Yes, this is normal behavior. This is because animation just rerenders View's pixels, but it's position on the display remains the same.

If you want to relocate your View to the place where your animation ends, you need to call View.layout() method and pass these 4 parameters, which describe Views new position on its layout.

Keep in mind that View.layout() gets params relative to `View's parent.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437