我有一个 texSwitcher,我向其中添加了两个文本视图(使用 TextView 类动态创建)。我正在使用手势检测器在子文本视图之间切换。但是当文本很大以适合当前的可视区域时,滚动不适用于 textswitcher。
当我尝试使用子文本视图的 setTextMovement 方法时,TextSwitcher 停止收听水平滑动手势。
有没有人成功地在 TextSwitcher 中显示可滚动的文本视图。
我通过创建自己的 TextSwitcher 解决了这个问题。
public class MyOwnSwitcher extends ViewSwitcher {
public MyOwnSwitcher (Context context) {
super(context);
}
public MyOwnSwitcher (Context context, AttributeSet attrs) {
super(context, attrs);
}
}
我将我的“onTouchEvent”方法移到了那个新类中。然后我不得不像这样覆盖“onInterceptTouchEvent”-Method:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
onTouchEvent(ev);
return super.onInterceptTouchEvent(ev);
}
我还必须将我的一些字段和变量从我的 Activity 移动到那个新类。但是你也可以使用你的活动方法:
Activity ac = (Activity) this.getContext();
那应该返回您的活动。