Can't add more than 2 views to a ViewSwitcher
生活随笔
收集整理的這篇文章主要介紹了
Can't add more than 2 views to a ViewSwitcher
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近使用到? TextSwitcher 來實現文字上下輪播的效果,出現了
Can't add more than 2 views to a ViewSwitcher
看了下源碼
/*** {@inheritDoc}** @throws IllegalStateException if this switcher already contains two children*/@Overridepublic void addView(View child, int index, ViewGroup.LayoutParams params) {if (getChildCount() >= 2) {throw new IllegalStateException("Can't add more than 2 views to a ViewSwitcher");}super.addView(child, index, params);}
我的出現問題的原因是第一次沒有問題顯示,再次返回這個界面的時候提示的,也就是有addView 一次
于是我寫了一個判斷當getChildCount<2 的時候 在list? 調用 setFactory 方法,這樣就好了。
自己判斷的代碼
?
總結
以上是生活随笔為你收集整理的Can't add more than 2 views to a ViewSwitcher的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个害怕背叛的个性签名。
- 下一篇: 钢化玻璃多少钱一平方