2015-09-26 13 views
0

流明/顯示像這樣的文本的一部分:更新父文本時使用隱藏一個textSwither改變

txtDescription.setInAnimation(in); 
txtDescription.setOutAnimation(out); 
txtDescription.setFactory(new ViewSwitcher.ViewFactory() { 
      @Override 
      public View makeView() { 
       TextView textView = new TextView(ShopContentDetailActivity.this); 
       textView.setTextColor(getResources().getColor(R.color.NightDark)); 
       return textView; 
      } 
     }); 

並呼籲變革文本此方法:

private void changeDescription() { 
     if (displayShort) 
      txtDescription.setText(Html.fromHtml(shortDescription)); 
     else txtDescription.setText(fullDescription); 
     displayShort = !displayShort; 
    } 

我的問題是當用戶觸摸textSwitcher顯示文本並再次觸摸以隱藏它時,textSwitcher的父視圖(線性佈局)的高度保持爲文本顯示時的高度,而不更改其高度。
如何在更改文本時更新父視圖? (其確定當觸摸顯示全文)

回答

1

我解決我這樣的問題:(我認爲TextViews的TextSwutcher變化知名度看不見沒有GONE然後我用這個TRCK)

private void changeDescription() { 
     if (displayShort) { 
      txtDescription.setCurrentText(null); // this line change invisible textView visible but without text and make it height 0 and then set the second textView text 
      txtDescription.setText(Html.fromHtml(shortDescription)); 
     } else txtDescription.setText(shopContent.getDescription()); 
     displayShort = !displayShort; 

    } 

但是有一個問題對我的情況並不那麼重要:當你隱藏文本的一部分時,它就會閃爍。
如果我解決它,我會更新我的答案。

+1

我正要raport問題做谷歌,但我在你的答案出來。 TextViews的初始狀態是indeeed GONE,文本更改後是INVISIBLE。也許它應該反正報道 – murt