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>
我不确定如何将星星移开。
答案 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
*
* *
* * *
* * * *
* * * * *