Можно поместить TextView внутри ImageView? - PullRequest
0 голосов
/ 08 января 2019

Я программирую вращающуюся рулетку, которая содержит наказания, у меня есть элемент управления 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();

    }

}

1 Ответ

0 голосов
/ 09 января 2019

Вы можете использовать Frame Layout. В этом случае вы можете разместить свои взгляды там, где вы хотите

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...