从RemoteViews获取TextView以使其文本可滚动

3

我有一个使用RemoteView构建的通知服务。

RemoteView布局包含一个TextView,我想让它滚动。

我已经在xml中将其设置为跑马灯,一切正常。但现在我需要设置textView.setSelected(true),因此我需要以某种方式引用textView。

那么,如何从RemoteView获取textView来执行setSelected()?或者还有其他方法可以使通知中的文本滚动吗?

我尝试过

        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.notification, null);
        TextView text = (TextView) layout.findViewById(R.id.text);
        text.setSelected(true);

或者

         View v = views.apply(getApplicationContext(), null);
         TextView text = (TextView) v.findViewById(R.id.text);
         text.setSelected(true);

但是文本没有滚动...
这是我的XML:
<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:duplicateParentState="true"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="false"
    android:singleLine="true" >

    <requestFocus
        android:duplicateParentState="true"
        android:focusable="true"
        android:focusableInTouchMode="true" />
</TextView>
1个回答

3

这就足够了:

<TextView 
android:id="@+id/text" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:duplicateParentState="true" 
android:ellipsize="marquee" 
android:fadingEdge="horizontal" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:gravity="center" 
android:marqueeRepeatLimit="marquee_forever" 
android:scrollHorizontally="false" 
android:singleLine="true" > 
    <requestFocus android:duplicateParentState="true" 
        android:focusable="true" 
        android:focusableInTouchMode="true" /> 
</TextView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接