我如何在Android Studio中进行开发

时间:2019-07-20 13:03:07

标签: android

我在html中找到了这个作为计数器。我该如何在android studio中进行开发。目的是计算许多项目并在其中显示sample image is here

1 个答案:

答案 0 :(得分:0)

好吧,您可以构建一行TextView(每个数字位,然后创建一个函数来设置值)。


TextView TextView0 = findViewById(R.id.tv0);
TextView TextView1 = findViewById(R.id.tv1);
TextView TextView2 = findViewById(R.id.tv2);
TextView TextView3 = findViewById(R.id.tv3);
TextView TextView4 = findViewById(R.id.tv4);

public void setCounter(int counterVal){

//Let's say you have 5 TextViews so 5 digits
//We count the TextViews from left to right

String sCounter =""+counterVal;
Int devider= Math.pow(10, sCounter.size());
Int[] counterArray;

for(int i =0 ; i < sCounter.size(); i++){
counterArray[i] = counterVal /devider;
counterVal = counterVal - (counterArray [i] * devider);
devider/10;
}


TextView0.setText(""+(counterArray [0]));
TextView1.setText(""+(counterArray [1]));
TextView2.setText(""+(counterArray [2]));
TextView3.setText(""+(counterArray [3]));
TextView4.setText(""+(counterArray [4]));
}

这是您要寻找的吗? 您应该实现自定义动画来切换数字。