以下是我为了将某些视图的背景色的亮度从128增加到255而编写的代码,反之亦然。不幸的是,应该让它等待的处理程序运行不正常。请帮助我使用此代码。处理程序在Android中的功能中无法正常工作
有一个3x3矩阵,其中有9个视图。我随机更改任何一个单元格的不透明度。
LEVEL:我想要逐个更改的单元格数量。这里,LEVEL:3
color [9]:3x3包含9个视图的矩阵。
public void pattern() {
for(int i=0;i<LEVEL;i++) {
int rand= 0 + (int)(Math.random() * 8);
computer+=rand;
Log.d(" i :" , ""+i);
Log.d(" random :" , ""+rand);
Log.d("Pattern incoming " , ""+color[rand].getBackground().getAlpha());
color[rand].getBackground().setAlpha(128);
final int random=rand;
handler.postDelayed(new Runnable() {
@Override
public void run() {
color[random].getBackground().setAlpha(128);
Log.d("Inside handler " , ""+color[random].getBackground().getAlpha());
color[random].getBackground().setAlpha(255);
}
},2000);
color[rand].getBackground().setAlpha(128);
Log.d("Outside handler " , ""+color[rand].getBackground().getAlpha());
}
}
的Android监视器logcat的
11-06 04:21:27.267 30640-30640/com.example.aman D/ i :: 0
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 1
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/ i :: 1
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 3
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/ i :: 2
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 7
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 7
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
$$ - 11-06 04:21:27.267 30640-30640/com.example.aman D/Inside handler: 128
$$ - 11-06 04:21:27.267 30640-30640/com.example.aman D/Inside handler: 128
$$ - 11-06 04:21:27.267 30640-30640/com.example.aman D/Inside handler: 128
正如你可以看到“内部处理”是在它运行3次循环的结束打印。我只是经过“模式进入”之前通过以下方式“外面处理程序”期待“内部处理”来执行:
11-06 04:21:27.267 30640-30640/com.example.aman D/ i :: 0
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 1
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
$$ - 11-06 04:21:27.267 30640-30640/com.example.aman D/Inside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/ i :: 1
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 3
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
$$ - 11-06 04:21:27.267 30640-30640/com.example.aman D/Inside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/ i :: 2
11-06 04:21:27.267 30640-30640/com.example.aman D/ random :: 7
11-06 04:21:27.267 30640-30640/com.example.aman D/Pattern incoming: 128
$$ - 11-06 04:21:27.267 30640-30640/com.example.aman D/Inside handler: 128
11-06 04:21:27.267 30640-30640/com.example.aman D/Outside handler: 128
什么你期待在logcat中看到?你是什么意思处理程序无法正常工作?另外,请将它作为问题粘贴,以便我们无需在新窗口中打开即可看到它。 –
@DavidRawson。我在这里添加了logcat语句。我希望现在这个问题很清楚。您的帮助将受到高度赞赏。谢谢。 –
谢谢!这使得它更容易回答 –