我正在编写一个包含惩罚的旋转轮盘,我有一个可以旋转的ImageView控件(在ImageView内部,我有旋转轮的图像)。现在,我想让用户创建自定义惩罚。在旋转轮盘之前的视图中,用户可以输入自己的惩罚,并将字符串值传递给TextView。现在,我想弄清楚的是,是否可以将这些文本视图放在ImageView中,以便新的惩罚在旋转轮盘中旋转。
这是代码完整代码:
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); // 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) {
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();
}
}
答案 0 :(得分:0)
您可以使用框架布局。在这种情况下,您可以将视图放置在所需位置