樓下省去不必要的循環想法很好,但是代碼好像不對吧?應該把return換成break,這樣才是跳出循環。還有isSuccess還是應該賦值為false。
2015-08-24
mItemWitdh=(mWidth-mPadding*2-mMargin*(mColumn-1))/mColumn;
這個理解
這個理解
2015-08-08
如果檢查的時候有一個失敗直接返回,可以省去不必要的循環,效率更高!代碼如下:
private void checkSuccess()
{
for (int i = 0; i < mGamePintuItems.length; i++){
ImageView imageView = mGamePintuItems[i];
if (getImageIndexByTag((String) imageView.getTag()) != i) return;
。。。
mHandler.sendEmptyMessage(NEXT_LEVEL);
}
private void checkSuccess()
{
for (int i = 0; i < mGamePintuItems.length; i++){
ImageView imageView = mGamePintuItems[i];
if (getImageIndexByTag((String) imageView.getTag()) != i) return;
。。。
mHandler.sendEmptyMessage(NEXT_LEVEL);
}
2015-08-02
可以用Handler處理,定義常量private static final int REMOVE_VIEWS = 0x112;
在onAnimationEnd里面發送消息mHandler.sendEmptyMessage(REMOVE_VIEWS);
在Handler里面的handleMessage函數里面加個case進行處理
case REMOVE_VIEWS:
mAnimLayout.removeAllViews();
break;
在onAnimationEnd里面發送消息mHandler.sendEmptyMessage(REMOVE_VIEWS);
在Handler里面的handleMessage函數里面加個case進行處理
case REMOVE_VIEWS:
mAnimLayout.removeAllViews();
break;
2015-08-02
我也遇到過報空指針的異常,主要就是mAnimLayout.removeAllViews();
在onend里調用引起的。使用以下方法就可以解決掉該問題了,將remove操作放在handler中處理即可
Handler h=new Handler();
h.post(new Runnable() {
@Override
public void run(){
mAnimLayout.removeAllViews();
}
});
在onend里調用引起的。使用以下方法就可以解決掉該問題了,將remove操作放在handler中處理即可
Handler h=new Handler();
h.post(new Runnable() {
@Override
public void run(){
mAnimLayout.removeAllViews();
}
});
2015-07-28