How to rotate view by coordinates also in Android

First, correctly understand my question before voting,

I have an idea that, for example,

  <View
                    android:id="@+id/View01"
                    android:layout_width="280dp"
                    android:layout_height="150dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="50dp"
                    android:layout_marginTop="83dp"
                    android:background="#212121"
                    android:rotation="-5"
                    android:visibility="visible" />

and the conclusion is

image

you can see that when I use android: rotation = "- 5" , it rotates the views (black box), but their coordinates remain the same (blue rectangle).

I want to use the new Rect after rotation, but I can’t do it, I read about Rect.mapPoint , but still can’t achieve the goal, any help for this?

EDIT:

final xml looks like

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res/com.android.game.robbrygame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/vScrollview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:scrollbars="none" >

        <HorizontalScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/hScrollview"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scrollbars="none" >

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

                <View
                    android:id="@+id/View01"
                    android:layout_width="280dp"
                    android:layout_height="150dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="50dp"
                    android:layout_marginTop="83dp"
                    android:background="#212121"
                    android:rotation="-5"
                    android:visibility="visible" />

            </RelativeLayout>
        </HorizontalScrollView>
    </ScrollView>

</RelativeLayout>

and I have as many views as View01 etc .... !!!

0
1

getLocalVisibleRect()

View view01 = findViewById(R.id.View01);

view01.post(new Runnable() {
            @Override
            public void run() {
                view01.getLocalVisibleRect(rectf);
                Log.d("WIDTH        :", String.valueOf(rectf.width()));
                Log.d("HEIGHT       :", String.valueOf(rectf.height()));
                Log.d("left         :", String.valueOf(rectf.left));
                Log.d("right        :", String.valueOf(rectf.right));
                Log.d("top          :", String.valueOf(rectf.top));
                Log.d("bottom       :", String.valueOf(rectf.bottom));
   }
 });

.post()

0

All Articles