1

I'm trying to rotate the image as shown in the following bead images clockwise. But the problem is pretty much evident from the pictures i.e. the bead is getting disappeared.

enter image description here -> enter image description here -> enter image description here -> enter image description here -> enter image description here

Following is my xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center_vertical" >

        <!-- *******************************top 1 beads ************************** -->

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
            android:background="@null"
            android:layout_centerHorizontal="true" >

            <!--
                 <ImageView
                android:id="@+id/tasbih_thread"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="-5dp"
                android:src="@drawable/tasbih_thread" />
            -->

            <ImageView
                android:id="@+id/bead1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="81dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="65dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead33"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="3dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="2dp"
                android:layout_marginTop="3dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:layout_marginTop="78dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead32"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="164dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:layout_marginTop="98dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead31"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="3dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="184dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:layout_marginTop="120dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead30"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="3dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="5dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="148dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead29"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="208dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="176dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead28"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="212dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:layout_marginTop="203dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead27"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />

            <RelativeLayout
                android:id="@+id/allah_number_relative"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/tasbih_counter_star"
                android:gravity="center" >

                <TextView
                    android:id="@+id/allah_number_textview2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/green"
                    android:textSize="20sp"
                    android:textStyle="bold" />
            </RelativeLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="210dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="228dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead26"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <!-- *******************************top 8 beads ************************** -->

        <RelativeLayout
            android:id="@+id/tableRow2"
            android:layout_width="205dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:layout_marginTop="253dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead25"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="2dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="280dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead24"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="0dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="194dp"
            android:layout_height="wrap_content"
            android:background="@null"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="305dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead23"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="0dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="184dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:layout_marginTop="330dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead22"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="0dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead13"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="164dp"
            android:layout_height="wrap_content"
            android:background="@null"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="355dp"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead21"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="0dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="375dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead15"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="6dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="390dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead19"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="4dp"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead16"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_marginTop="6dp"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="53dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="402dp"
            android:background="@null"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/bead18"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:background="@drawable/tasbih_bead_desl" />

            <ImageView
                android:id="@+id/bead17"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:background="@drawable/tasbih_bead_desl" />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

</RelativeLayout>

Following is the translation function:

@Override
public void onWindowFocusChanged (boolean hasFocus){
    super.onWindowFocusChanged(hasFocus);
    if(hasFocus){
        int[] arr=new int[2];
        for(int i=0;i<33;i++)
        {
            ((ImageView)findViewById(image_drawable[i])).getLocationOnScreen(arr);
            xArrayList.add(arr[0]);
            yArrayList.add(arr[1]);
            Log.e("x= "+((ImageView)findViewById(image_drawable[i])).getRight(),"y= "+((ImageView)findViewById(image_drawable[i])).getBottom());
        }
    }
}

and following is the function to get the co-ordinates which is called onTouch of the screen:

private void startTranslateAnimation()
{
    for(int i=0;i<=32;i++)
    {
        int x1=xArrayList.get(i);
        int y1=yArrayList.get(i);
        int x2,y2;
        if(i<=31)
        {
            x2=xArrayList.get(i+1);
            y2=yArrayList.get(i+1);
        }
        else
        {
            x2=xArrayList.get(0);
            y2=yArrayList.get(0);
        }
        TranslateAnimation left_animation = new TranslateAnimation(0,x2-x1,0,y2-y1);
        left_animation.setDuration(2000);
        left_animation.setFillAfter(false);
        findViewById(image_drawable[i]).startAnimation(left_animation);
    }

  }

any help?

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86

0 Answers0