2013-05-04 81 views
0

我有一個texSwitcher,我添加了兩個文本視圖(使用TextView類動態創建)。我使用手勢檢測器在兒童文字視圖之間切換。但是,當文字很大以適應當前的可視區域時,滾動不適用於文本切換器。安卓在TextSwitcher中滾動文本

當我嘗試使用子文本視圖的setTextMovement方法時,然後TextSwitcher停止監聽水平輕掃手勢。

有沒有人成功地在TextSwitcher中顯示可滾動的文本視圖。

回答

2

我用創建自己的TextSwitcher解決了這個問題。

public class MyOwnSwitcher extends ViewSwitcher { 
    public MyOwnSwitcher (Context context) { 
     super(context); 
    } 

    public MyOwnSwitcher (Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
} 

我將我的「onTouchEvent」 - 方法轉移到該新類中。然後,我不得不重寫「onInterceptTouchEvent」 - 方法類似:

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    onTouchEvent(ev); 
    return super.onInterceptTouchEvent(ev); 
} 

我也不得不搬到我的一些字段和變量的從我的活動到新類。 但你也可以用你的活動方式也有:

Activity ac = (Activity) this.getContext(); 

應該返回自己的活動。