Android:无法设置选框

时间:2014-03-22 17:00:23

标签: android xml marquee

我无法在android中实现Marquee Text View。

是的,这个问题类似于与Marquee相关的许多其他问题。我读过大部分内容。我尝试以许多答案的方式实现Marquee。但我的代码仍无效。

请帮我解决这个问题。我尝试了一切。没有任何效果。

感谢。

XML代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@color/mainBg"
    tools:context=".MainActivity" >

<TextView android:layout_width="fill_parent"
    android:id="@+id/marquee"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:lines="1"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:text="@string/home"
    android:fontFamily="monospace"
    android:textStyle="bold"
    android:paddingBottom="20dp" />
</LinearLayout>

JAVA代码:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView marqText  = (TextView)findViewById(R.id.marquee);
    marqText.setSelected(true);
}

2 个答案:

答案 0 :(得分:1)

如果 routingConfig: accessKeyId: AKIAVL34FWX5KFDFBSTNCND recordSet: type: A ttl: 60 resourceIp: 52.41.8.70 secretAccessKey: IglNnjk/iaR++DnQuNObDFBAnrXsvsd9ZO+gJW5nZDd hostedZoneId: Z03431513GGUF3XEADGBDQE5U 填满整个宽度,则需要添加这些代码行

TextView

也不要忘记为<TextView . . android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" /> 设置selected

TexrtView

如果 textview.setSelected(true); 没有填充宽度,唯一的方法就是调用这个方法并将 TextView 传递给它。

TextView

注意:此方法仅在 textView 宽度为 fun addMarquee(textView: TextView) { textView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { val pixels = textView.measuredWidth - 1 val params = textView.layoutParams params.width = pixels textView.layoutParams = params textView.isSelected = true textView.ellipsize = TextUtils.TruncateAt.MARQUEE textView.isSingleLine = true textView.marqueeRepeatLimit = -1 textView.viewTreeObserver.removeOnGlobalLayoutListener(this) } }) } 时有效。

答案 1 :(得分:0)

尝试将android:singleLine = "true"添加到TextView,以使文字只保留一行。

相关问题