我在Frame Layout中有一个ImageView和TextView,我可以旋转该Image View,但是仍然无法弄清楚如何旋转Frame Layout,这里我使用ImageView旋转的代码,我认为这是如果有办法或者有更好的办法让我本质上知道我想做的是一个包含惩罚的旋转轮盘,我有一个可以旋转的ImageView(在ImageView里面有旋转轮的图像)。现在,我想让用户创建自定义惩罚。在旋转轮盘之前的视图中,用户可以输入自己的惩罚,并将字符串值传递给TextView。现在,我正在尝试确定是否可以将这些文本视图放在ImageView中,以便在旋转轮盘中旋转新的惩罚。
public void actionRoulette(View view) {
int corner = 360/38; // corner for point
int randPosition = corner * new Random().nextInt(38); // random point
int MIN = 5; // min rotation
int MAX = 9; // max rotation
long TIME_IN_WHEEL = 1000; // time in one rotation
int randRotation = MIN + new Random().nextInt(MAX-MIN); // random rotation
int truePosition = randRotation * 360 + randPosition;
long totalTime = TIME_IN_WHEEL * randRotation + (TIME_IN_WHEEL/360) * randPosition;
Log.d("ROULETTE_ACTION","randPosition : " + randPosition
+ " randRotation : " + randRotation
+ " totalTime : " + totalTime
+ " truePosition : " + truePosition);
ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",0f,(float)truePosition);
animator.setDuration(totalTime);
animator.setInterpolator(new DecelerateInterpolator());
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
imageRoulette.setEnabled(false);
}
@Override
public void onAnimationEnd(Animator animator) {
imageRoulette.setEnabled(true);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();