2017-10-17 167 views
0

我想模糊一個ListView項目。我模糊的CustomListViewAdapter的getView()(使用模糊庫):如何模糊ListView項目與模糊?

@Override 
    public View getView(final int position, View convertView, final ViewGroup parent) { 
     final AirdropResult airdrop = getItem(position); 
     boolean bWasNull = false; 
     if (convertView == null) { 
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.result_item, parent, false); 
      bWasNull = true; 
     } 

     final RelativeLayout airdropListRowInside = (RelativeLayout) convertView.findViewById(R.id.airdropListRowInside); 

     final TextView tvName = (TextView) airdropListRowInside.findViewById(R.id.tvCoinName); 
     final TextView tvDesc = (TextView) airdropListRowInside.findViewById(R.id.tvDesc); 
     final TextView tvStartdate = (TextView) airdropListRowInside.findViewById(R.id.tvStartdate); 

     tvName.setText(airdrop._name); 
     tvDesc.setText(airdrop._shortdesc); 

     if(bWasNull) { 
      convertView.post(new Runnable() { 
       @Override 
       public void run() { 
        Blurry.with(getContext()) 
          .radius(5) 
          .sampling(2) 
          .async() 
          .animate(100) 
          .onto(airdropListRowInside); 
       } 
      }); 
     } 

     return convertView; 
    } 

enter image description here

好像佈局變得模糊,但隨後呈現在上面不模糊的佈局(只有一個佈局)。我使用Runnable because it is apparently needed

我假設這是因爲ListView如何重用項目,但沒有足夠的理解來解決它。有人可以幫忙嗎?

+0

Post Full'getView()'方法 –

+0

發佈完整實現。 –

回答

0

這是因爲您的bWasNull是在getView()內定義的。因此當getView()被再次調用時,它總是被重置爲false,這次convertView不是null因此bWasNull不是真實的,並且Blurry未被應用於新的convertView

Define bWasNullgetView()之外。 B.T.W我沒有看到使用這個bWasNull

+0

我不認爲這是問題。如果每次調用getView()都會模糊圖像,那麼它會多次模糊,並且會產生模糊的黑色效果。 –