我希望按鈕中的文本滾動...所以爲此,我使用按鈕上的文本視圖。 我在佈局中設置了以下屬性。但它不起作用。 我在RelativeLayout
中使用這個...任何人都可以告訴我我的代碼有什麼問題嗎?Android,文本中的水平滾動查看
<TextView
android:id="@+id/textView1"
android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"
android:layout_width="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_height="wrap_content"/>
我得到了解決,我分享這個...我創建了一個類
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
public class ScrollingTextView extends TextView {
public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollingTextView(Context context) {
super(context);
}
@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;
}
}
因爲我需要一個以上的TextView
要在屏幕上滾動... 未來在layout.xml
文件用這個....
<com.yourpackage.ScrollingTextView
android:id="@+id/TextView01"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:padding="5dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="1.option" />
瞧....它做
的可能重複[有沒有辦法讓橢圓大小=「選框」總是滾動?](http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll) – Sam
我得到了這個問題的解決方案.... –