我如何将星星移到它所属的地方

时间:2018-10-13 21:40:45

标签: java recursion

enter image description here 那是我在上面链接中的作业。这是我到目前为止所做的:

package com.example.alexander.compassvsredneckinterpretertimetable;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ShapeDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.constraint.ConstraintLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class testActivity extends Activity
{
    class testUI
    {
        LinearLayout linearLayout;
        TextView start;
        TextView end;

    int startValue, endValue;

    private ShapeDrawable makeBackgorundShape()
    {
        ShapeDrawable BackgroundShape = new ShapeDrawable();
        BackgroundShape.setShape(ItemBackground.makeRoundRect());
        BackgroundShape.getPaint().setColor(0xffa6b2fc);
        return BackgroundShape;
    }

    testUI(Context context, final ConstraintLayout parent, int startValue_, int endValue_)
    {
        this.startValue = startValue_ * 100;
        this.endValue = endValue_ * 100;

        start = new TextView(context);
        start.setText(".        " + String.valueOf(endValue) + "        .");

        end = new TextView(context);
        end.setText(".        " + String.valueOf(startValue) + "        .");

        linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.addView(start);
        linearLayout.addView(end);
        linearLayout.setBackground(makeBackgorundShape());

        parent.addView(linearLayout);

        final Handler handler = new Handler();

        Runnable runnable = new Runnable()
        {
        @Override
            public void run()
            {
                linearLayout.layout(parent.getLeft(), linearLayout.getTop() + startValue, parent.getRight(), linearLayout.getBottom() + endValue); //without being postDelayed, this doesn't work
            }
        };

        handler.postDelayed(runnable, 1000);
        //handler.post(runnable); //doesn't work
    }
}

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);

    ConstraintLayout constraintLayout = findViewById(R.id.constLayout);

    new testUI(this, constraintLayout, 8, 10);
    }
}

当我运行它时,第一个*不合适,我不确定错误是什么。下面的链接是该程序的示例运行。

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/constLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".testActivity">
</android.support.constraint.ConstraintLayout>

我不确定如何将星星移开。

1 个答案:

答案 0 :(得分:0)

在基本情况下:

if (n == 1) {

    System.out.print("\t\t");
    for (int i = 1; i <= t - 1; i++)
        System.out.print(" ");

    System.out.println("*");
}

您正在打印两个选项卡所需的空格数。您需要删除System.out.print("\t\t");

if (n == 1) {
    for (int i = 1; i <= t - 1; i++)
        System.out.print(" ");
    System.out.println("*");
}

输出:

Enter number of rows of pins: 5
    *
   * * 
  * * * 
 * * * * 
* * * * *