对于我的情况,即使在我尝试了stackoverflow中提供的多个解决方案后,选取框仍然无效。
这是我的xml内容: ...
.... // XML for Other Views here
<TextView android:id="@+id/progress"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:gravity="center"
android:layout_weight="2"
/>
</LinearLayout>
...
设置了所有需要(或可能需要)的属性,对吗?
下面是我在代码中使用TextView的方式:
1)此TextView是片段的一个组件。
2)此组件位于Fragment的回调函数中:onAcitvityCreated()
,如下所示:
m_progressView = (TextView) m_activity.findViewById(R.id.progress);
注意:m_activity是片段所属的活动。
3)然后在setSelected(true)
之后调用setText()
,如下所示:
m_activity.postDelayed(new Runnable(){
public void run()
{
m_progressView.setEllipsize(TruncateAt.MARQUEE);
m_progressView.setText(new String("第" + g_currentPage + "页 共" + g_totalPages + "页"));
m_progressView.setSelected(true);
}
}, 500);
但它不起作用。
当我打开eclipse的logcat时,我得到循环日志,如:
07-28 19:30:31.639: I/SurfaceTextureClient(20944): [STC::queueBuffer] this:0x5a8be558) fps:1.93, dur:1038.04, max:549.31, min:488.73
07-28 19:30:32.645: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.99, dur:1006.23, max:507.58, min:498.65
07-28 19:30:33.661: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.97, dur:1015.59, max:512.58, min:503.00
07-28 19:30:34.716: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.90, dur:1054.77, max:543.55, min:511.22
07-28 19:30:36.230: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.98, dur:1514.01, max:534.81, min:460.85
07-28 19:30:37.733: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:2.00, dur:1502.85, max:507.72, min:493.80
07-28 19:30:38.761: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.94, dur:1028.36, max:535.38, min:492.98
07-28 19:30:39.771: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.98, dur:1009.94, max:506.94, min:503.01
07-28 19:30:40.772: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:2.00, dur:1000.87, max:514.48, min:486.39
07-28 19:30:41.815: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.92, dur:1043.46, max:531.82, min:511.64
07-28 19:30:42.860: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.91, dur:1044.70, max:543.25, min:501.45
07-28 19:30:44.357: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:2.00, dur:1496.71, max:508.20, min:481.11
07-28 19:30:45.381: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.95, dur:1024.39, max:531.66, min:492.74
07-28 19:30:46.420: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:2.89, dur:1039.11, max:511.83, min:66.67
07-28 19:30:47.476: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.89, dur:1056.07, max:531.04, min:525.03
07-28 19:30:48.481: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.99, dur:1004.86, max:511.82, min:493.04
07-28 19:30:49.493: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.98, dur:1011.62, max:533.93, min:477.69
07-28 19:30:50.530: I/SurfaceTextureClient(20944): [STC::queueBuffer] (this:0x5a8be558) fps:1.93, dur:1037.57, max:563.91, min:473.67
似乎字幕机制正在根据这些日志工作,但为什么文本不会移动?
非常感谢。
答案 0 :(得分:0)
你可以做这样的事情
<TextView
android:id="@+id/fact"
android:layout_width="200dp"
android:layout_height="40dip"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Loading... More text to see if it spans or not and want more">
<requestFocus
android:duplicateParentState="true"
android:focusable="true"
android:focusableInTouchMode="true" />
</TextView>