在带有选框的TextView中,不会开始循环

时间:2013-03-20 11:10:54

标签: android marquee

我有一个大布局和一个虚拟布局,其中只包含文本视图。两种情况下的文本视图小部件都是相同的,但是当放入更复杂的布局时,它不起作用。

这个选框有什么限制吗?

<TextView
    android:id="@+id/txt_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    android:text="a sdasd as das d as d asd a sd as d a sd as d as das d a sd a" >
</TextView>

3 个答案:

答案 0 :(得分:1)

在我的情况下android:focusable="true“和android:focusableInTouchMode="true"进行测试循环:

<TextView
    android:id="@+id/txt_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:marqueeRepeatLimit="marquee_forever"
    android:maxLines="1"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:text="some long text">
</TextView>

答案 1 :(得分:0)

试试这个:

<TextView
            android:id="@+id/txt_id"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="a sdasd as das d as d asd a sd as d a sd as d as das d a sd a" >
        </TextView>

答案 2 :(得分:0)

这是实现marque的另一种方法。这对我来说非常合适。

将其用作textview

 <com.example.marque_test.marque_textView
        android:id="@+id/TV_FOOTER"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         android:fadingEdge="horizontal"
           android:scrollHorizontally="true"
           android:text="a sdasd as das d as d asd a sd as d a sd as d as das d a sd a"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="center"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true"
        />

marque_textView.java

public class marque_textView extends TextView
{
   public marque_textView(Context context)
   {
           super(context);
           // TODO Auto-generated constructor stub
   }

   public marque_textView(Context context, AttributeSet attrs,int defStyle)
   {
   super(context, attrs, defStyle);
   setEllipsize(TruncateAt.MARQUEE);

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

   @Override
   protected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect)
   {
       if (focused)
       {
           super.onFocusChanged(focused, direction, previouslyFocusedRect);
       }
   }

   @Override
   public void onWindowFocusChanged(boolean focused)
   {
       if (focused)
       {
           super.onWindowFocusChanged(focused);
       }
   }

   @Override
   public boolean isFocused()
   {
       return true;
   }
}