Android TextView Marquee无法正常工作

时间:2017-01-12 05:41:13

标签: android android-layout textview marquee

Marquee无法使用我的TextView请检查以下代码

TextView

XML代码

                          <TextView
                            android:id="@+id/mtextcash"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="30dp"
                            android:ellipsize="marquee"
                            android:fadingEdge="horizontal"
                            android:gravity="center"
                            android:marqueeRepeatLimit="marquee_forever"
                            android:maxLength="5"
                            android:scrollHorizontally="true"
                            android:scrollbars="horizontal"
                            android:singleLine="true"
                            android:text="Simple application that shows how to use marquee, with a long text"
                            android:textColor="@color/white"
                            android:textColorHint="@color/white"
                            android:textSize="25dp" />

活动OnCreate

TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
inputAvailableCash.setSelected(true);

先谢谢

7 个答案:

答案 0 :(得分:7)

由于文本非常长,并且只有在单行编写文本时才能使用代码。要么添加

 android:singleline="true" 

在xml中或将您的java代码更改为。

  TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
        inputAvailableCash.setSelected(true);
         inputAvailableCash.setSingleLine(true);

这肯定会对你有用。

答案 1 :(得分:1)

在xml文件中添加此属性

 var setDefaultDate = new Date();
    $scope.defaultStartDate = moment(setDefaultDate).format('MM/DD/YYYY');


    jQuery('#startDatepicker').datetimepicker({
        format: 'MM/DD/YYYY',
        defaultDate: new Date()
    });

    jQuery('#startDatepicker').data("DateTimePicker").minDate($scope.defaultStartDate);


    jQuery("#startDatepicker").on("dp.change", function(e) {
        jQuery('#startDatepicker').focus();     
    });

答案 2 :(得分:1)

尝试将这些参数放到TextView上 - 它可以正常工作

android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"

你还需要setSelected(true):

 my_TextView.setSelected(true);

答案 3 :(得分:1)

对于选框效果,宽度应始终为“match_parent”或静态(如200dp ...等)。并以编程方式将setSelected设为true,然后将其宽度设置为xml中的match_parent,它将起作用。

编辑xml:

                     <TextView
                        android:id="@+id/mtextcash"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="30dp"
                        android:ellipsize="marquee"
                        android:fadingEdge="horizontal"
                        android:gravity="center"
                        android:marqueeRepeatLimit="marquee_forever"
                        android:maxLength="5"
                        android:scrollHorizontally="true"
                        android:scrollbars="horizontal"
                        android:singleLine="true"
                        android:text="Simple application that shows how to use marquee, with a long text"
                        android:textColor="@color/white"
                        android:textColorHint="@color/white"
                        android:textSize="25dp" />

如果通过执行match_parent它将影响您的设计,那么您必须通过修复它的宽度或以其他方式来管理它。

根据您的xml代码,您使用的是android:maxLength =“5”表示只输入5个字符,因此您可以将其宽度修正为50dp或任何其他静态大小。

答案 4 :(得分:1)

嘿,检查这段代码,但是当你的文字大小,即长度更长时,大帐号工作。在我这边工作。:)

q=$(date +%H)
x=-12
while [ "$x" -le 11 ]
do
  y=$(TZ=UTC"$x" date +%H)
  if [ "$y" = "$q" ]
  then
    printf '%+03d00\n' "$((-x))"
    break
  fi
  x=$((x + 1))
done

希望这会有所帮助。:)

答案 5 :(得分:0)

<TextView android:id="@+id/mtextcash"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:ellipsize="marquee"
                   android:gravity="center"
                   android:marqueeRepeatLimit="marquee_forever"
                   android:scrollHorizontally="true"
                   android:singleLine="true"
                   android:text="Simple application that shows how to use marquee, with a long text"
                   android:textColor="@color/white"
                   android:textColorHint="@color/white"
                   android:textSize="25dp" />

答案 6 :(得分:0)

TextView 上运行选取框的最低代码是

<TextView
    .
    .
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

也不要忘记如下设置selected

textview.setSelected(true);