我有一个容器布局。它有一个ImageView
和一个TextView
内部,我想旋转容器布局。我现在有一个ImageView的代码,我尝试使用相同的逻辑旋转容器布局,但是我可以使它正常工作是代码还好还是我所缺少的?
或者还有其他方法可以同时旋转ImageView
和TextView
?
public class ruleta4F extends AppCompatActivity {
private ImageView imageRoulette;
private FrameLayout mainView;
TextView ruletaNombre;
TextView castigo1,castigo2,castigo3,castigo4;
TextView nombreRuleta4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ruleta4_f);
imageRoulette = (ImageView) findViewById(R.id.image_roulette);
mainView = (FrameLayout) findViewById(R.id.mainView);
/////////////////get data
ruletaNombre = (TextView) findViewById(R.id.textView12);
String name = getIntent().getStringExtra("namer");
ruletaNombre.setText(name);
castigo1 = (TextView) findViewById(R.id.textView7);
String sc1 = getIntent().getStringExtra("sc1");
castigo1.setText(sc1);
castigo2 = (TextView) findViewById(R.id.textView8);
String sc2= getIntent().getStringExtra("sc2");
castigo2.setText(sc2);
castigo3 = (TextView) findViewById(R.id.textView10);
String sc3= getIntent().getStringExtra("sc3");
castigo3.setText(sc3);
castigo4 = (TextView) findViewById(R.id.textView11);
String sc4= getIntent().getStringExtra("sc4");
castigo4.setText(sc4);
}
public void actionRoulette(View view) {
int corner = 360/38; // corner for point
int randPosition = corner * new Random().nextInt(38);
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) {
mainView.setEnabled(false);
}
@Override
public void onAnimationEnd(Animator animator) {
mainView.setEnabled(true);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();
}
}