Java 可以在ImageView中放置TextView吗?
我正在编程一个包含惩罚的旋转轮盘赌,我有一个可以旋转的ImageView控件(在ImageView中我有旋转的轮子的图像)。现在我想让用户创建自定义惩罚。在旋转轮盘赌之前的视图中,用户可以输入自己的惩罚&它将字符串值传递给TextView。现在我想弄清楚的是,是否有可能将这些文本视图放在ImageView中,以便新的惩罚在旋转的轮盘赌中旋转 以下是代码完整代码:Java 可以在ImageView中放置TextView吗?,java,android,android-studio,Java,Android,Android Studio,我正在编程一个包含惩罚的旋转轮盘赌,我有一个可以旋转的ImageView控件(在ImageView中我有旋转的轮子的图像)。现在我想让用户创建自定义惩罚。在旋转轮盘赌之前的视图中,用户可以输入自己的惩罚&它将字符串值传递给TextView。现在我想弄清楚的是,是否有可能将这些文本视图放在ImageView中,以便新的惩罚在旋转的轮盘赌中旋转 以下是代码完整代码: public class ruleta4F extends AppCompatActivity { private Image
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();
}
}
可以使用框架布局。在这种情况下,您可以将视图放置在所需的位置将TextView和ImageView放置在容器布局内,并旋转该容器布局?如果您对在图像内绘制文本感兴趣,请查看,但我确信这不是解决问题的最佳解决方案我找不到容器布局,确切的名称是什么?好的,我把TextView和ImageView放在容器布局中,我更改了代码,但文本仍然不移动,只移动图像,我将更新代码。能给我一个简短的特写吗?嘿,我在框架布局中有ImageView和TextView,但仍然无法在代码中找出如何旋转框架布局,你能帮我吗?