动画时图像会改变高度和宽度为什么会这样?

时间:2015-02-12 10:53:17

标签: java android android-layout android-animation

我有一个轮盘赌的图像,它在动画时会改变它的形状和大小。我正在使用位图。我知道它的宽度和高度有一个解决方案,但我没有任何解决方案。

代码如下。

* .java(文件)

import java.util.Random;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class SpinActivity extends Activity {
    boolean clickcount = false;
    ImageView switchon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spin);

        switchon = (ImageView) findViewById(R.id.imageSwitchOn);
        final ImageView roullete = (ImageView) findViewById(R.id.wheel_image);
        final ImageView innerroullete = (ImageView) findViewById(R.id.innerroullete);
        final Animation anim1 = AnimationUtils.loadAnimation(SpinActivity.this,
                R.anim.wheel_spin_anim);
        final Animation anim2 = AnimationUtils.loadAnimation(SpinActivity.this,
                R.anim.innner_roullete_animation);
        final Animation anim3 = AnimationUtils.loadAnimation(SpinActivity.this,
                R.anim.from_middle);
        final View l = findViewById(R.id.flipId);
        final TextView team1 = (TextView) findViewById(R.id.textView1);
        final TextView team2 = (TextView) findViewById(R.id.textView2);
        final View full = findViewById(R.id.full_view);
        full.setRotationX(30);


        switchon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {



                roullete.startAnimation(anim1);


                int i2, i1 = 0;
                float i3;

                Random r = new Random();
                i2 = r.nextInt(2);  
                i1 = r.nextInt(11 - 1 + 1) + 1;
                 i3 = (float) ((i1/1.746031)+2.605);
                 float i4 = (float) (i3*(180/3.14159265));

                Bitmap myImg = BitmapFactory.decodeResource(getResources(),
                        R.drawable.roulete_hd);
                roullete.setImageBitmap(myImg);

                Matrix matrix = new Matrix();

                matrix.postRotate(360-i4);
                l.startAnimation(anim2);
                l.startAnimation(anim3);
                Log.d("ANSWER :-  ", i1 + ": ");
                Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0,
                        myImg.getWidth(), myImg.getHeight(), matrix, true);

                roullete.setImageBitmap(rotated);

                if (i2 == 1) {
                    team1.setText("Team1");
                    team2.setText("Team2");
                } else {
                    team1.setText("Team2");
                    team2.setText("Team1");
                }



            }


        });

    }
}

* .xml(文件)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/full_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top" >

    <ImageView
        android:id="@+id/wheel_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:contentDescription="Spinning Roulette Wheel"
        android:src="@drawable/roulete_hd" />

    <RelativeLayout
        android:id="@+id/flipId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" >

        <ImageView
            android:id="@+id/innerroullete"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:contentDescription="Spinning Roulette Wheel"
            android:src="@drawable/inner_roullete2" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="20dp"
            android:layout_centerHorizontal="true"
            android:text="Team1"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="80dp"
            android:text="Team2"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </RelativeLayout>

    <ImageView
        android:id="@+id/imageSwitchOn"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_centerInParent="true"
        android:src="@drawable/start_button" />

</RelativeLayout>

0 个答案:

没有答案