gpt4 book ai didi

java - Android 在 TextSwitcher 中滚动文本

转载 作者:行者123 更新时间:2023-12-02 07:03:25 26 4
gpt4 key购买 nike

我有一个 texSwitcher,我向其中添加了两个 TextView (使用 TextView 类动态创建)。我正在使用手势检测器在子 TextView 之间切换。但是,当文本太大而无法容纳当前可视区域时,滚动对于文本切换器不起作用。

当我尝试使用子 TextView 的 setTextMovement 方法时,TextSwitcher 停止监听水平滑动手势。

有人成功地在 TextSwitcher 中显示可滚动 TextView 吗?

最佳答案

我通过创建自己的 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 移至新类。但您也可以使用您的 Activity 方法:

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

这应该返回您的 Activity 。

关于java - Android 在 TextSwitcher 中滚动文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16372510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com