2013-03-20 32 views
0

我有一個大的佈局和一個只有文本視圖的虛擬佈局。在兩種情況下,文本視圖小部件都是相同的,但是當放入更復雜的佈局時,它不起作用。在帶有選取框的TextView中不啓動循環

對選取框有任何限制嗎?

<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> 

回答

0

在我的情況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> 
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> 
+0

我試過,但它不不解決問題。在我的虛擬項目中一切正常,但是當我將這個textview小部件放在更復雜的佈局結構中時,它不起作用 – Lukap 2013-03-20 12:54:40

0

這裏是實現marque.This工作完美的我的另一種方法。

將此作爲文本視圖使用

<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; 
    } 
} 
相關問題