如何在Android

时间:2017-07-25 06:12:47

标签: java android

 private void generateView() {
        for (int i = 0; i < 5; i++) {
            mview = new View(getActivity());
            mview.setBackgroundResource(R.color.grayColor);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    10, 40);
            layoutParams.setMargins(5, 0, 5, 0);
            mview.setLayoutParams(layoutParams);
            lnLinearlayout.addView(mview);
            changeProgress();
        }
    }


    public void changeProgress()

    {

        new Thread(new Runnable() {
            @Override
            public void run() {
                    // Update the progress status

                    for (int i = 0; i < lnLinearlayout.getChildCount() - 1; i++) {
                        final int finalI = i;
                        progressStatus = i;
                        // Try to sleep the thread for 20 milliseconds
                        try {

                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                        // Update the progress bar
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                lnLinearlayout.getChildCount();
                                     lnLinearlayout.getChildAt(finalI).setBackgroundResource(R.color.blackcolor);


                            }

                        });

                    }
                }

        }).start(); // Start the operation
    }

这是我的代码我能够创建前5个视图并将其颜色从灰色更改为黑色。我试图重新创建相同的视图和相同的过程,当它到达第五位置视图和相同的过程应该发生,直到停止线程可以任何人请建议我如何做到这一点?

0 个答案:

没有答案