2015-07-03 24 views
1

我需要的TextView這將閃爍的文字變化 - 所以我讓CustomTextView像here描述。它工作的很好,但我有問題,當我在列表項中設置該CustomTextView。因爲ListView的項目都被重用我CustomTextView保持滾動時向上/向下,因爲它的環境的變化,現在「點」到另一個列表項閃爍。Android的列表項重用

問題是我不知道如何來確定何時該項目的背景下發生變化,所以我不能把noFlash標誌(文本的CustomTextView的屬性設置爲null,所以我不能使用,要麼)

+0

什麼觸發動畫?設置文本屬性?發現問題可能會有問題,因爲text屬性的設置可能有多種原因:更改文本,填充現有值而不是更改以及回收視圖。聽起來只有第一個案例才能觸發動畫。我會將animate公開爲一種方法,並讓知道更多關於當前上下文的調用者決定何時進行動畫製作。 – Kiliman

+0

通過設置新的屬性AnimationText觸發動畫。 AnimationText綁定(通過mvvmcross)到UI。 AnimationText設置控件的Text屬性。所有這一切都在我提供的鏈接描述(它只是其他類型的動畫),但你得到了一點 - 我想知道是用什麼方法重用列表項,回收視圖中設置AnimatingText財產...... – ozapa

+0

你可以嘗試實施某種小區自己的重用跟蹤'OnAttachedToWindow'和'OnDetachedFromWindow' https://github.com/MvvmCross/MvvmCross/blob/3.5/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxBaseListItemView.cs #L59 - 或者可能在某些自定義適配器代碼中 – Stuart

回答

0

在最後,我不得不做出定義適配器與一些代碼BindBindbleCode

protected override void BindBindableView(object source, IMvxListItemView viewToUse) 
{ 
    var newValue = source as ListItemVM; 
    var oldValue = viewToUse.DataContext as ListItemVM; 

    if (newValue.ItemID != oldValue.ItemID) 
     newValue.Rebinded = true; 

    base.BindBindableView(source, viewToUse); 
} 

然後我加入NotLoaded財產上CustomTextView和綁定這兩個在一起。因此,當Rebinded爲true時,它會將NotLoaded設置爲true,表示該TextView中的數據未加載。如果數據未加載,則不需要刷新CustomTextView的背景。

public string AnimatingText 
{ 
    get { return Text; } 
    set 
    { 
     if (Text == value) 
      return; 


     if (NotLoaded) 
     { 
      Text = value; 
      NotLoaded = false; 
      return; 
     } 

     Text = value; 
     // Do your animation here 
    } 
}