Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓:围绕中心旋转图像?_Java_Android_Animation_Rotation - Fatal编程技术网

Java 安卓:围绕中心旋转图像?

Java 安卓:围绕中心旋转图像?,java,android,animation,rotation,Java,Android,Animation,Rotation,我希望图像围绕其中心旋转,但我的方法不起作用,它显然是围绕不同的轴心点旋转的。我是Android开发新手,所以你可能会在我的代码中发现一些严重的错误。此外,如果我旋转屏幕,图像将旋转回其初始旋转。 这是我的档案: fragment_main.xml <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layo

我希望图像围绕其中心旋转,但我的方法不起作用,它显然是围绕不同的轴心点旋转的。我是Android开发新手,所以你可能会在我的代码中发现一些严重的错误。此外,如果我旋转屏幕,图像将旋转回其初始旋转。 这是我的档案:

fragment_main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivityFragment"
        android:background="@drawable/texture">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Πάγωσε η κόλαση..."
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_0"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:paddingTop="25dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Μπρρρ!"
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="50dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Κρύο"
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_2"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="75dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Έτσι κ'έτσι..."
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_3"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Καλό"
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_4"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="125dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Πολύ καλό!"
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_5"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="150dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Κάνεις κοιλιακούς!"
            android:textColor="@color/label_color"
            android:textSize="20dp"
            android:id="@+id/label_6"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="175dp" />

        <ImageView
            android:src="@drawable/thermostat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/thermostat"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:paddingTop="@dimen/margin" />

        <ImageView
            android:src="@drawable/thermostat_slider"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/thermostat_slider"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:paddingTop="@dimen/margin" />

        <ImageView
            android:src="@drawable/inside_thing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/inside_thing"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:paddingTop="@dimen/margin" />

        <ImageView
            android:src="@drawable/inside_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/inside_text"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:paddingTop="@dimen/margin" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Τι κάνω?"
            android:textColor="@color/label_color"
            android:textStyle="bold"
            android:id="@+id/title"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/title_margin"/>

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text"
            android:text="@string/help_text"
            android:textColor="@color/label_color"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="750dp" />

        </RelativeLayout>
</ScrollView>
试试这个:

 Animation a = new RotateAnimation(0.0f, 90.0f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                    0.5f);

这在第一次实际上不起作用,但后来我把枢轴改成了0.58f,现在它起作用了!不知道为什么,但无论如何,谢谢你!还有一件事:当屏幕也旋转时,如何保持旋转?我认为当屏幕旋转时,它会保持旋转。
 Animation a = new RotateAnimation(0.0f, 90.0f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                    0.5f);