如何使用小文本在android中添加marquee到TextView

时间:2014-12-19 12:00:46

标签: android android-activity android-fragments marquee

我想在我的应用程序中将Marquee功能应用于TextView,并且我已经成功实现了它。这是我用过的代码。

<TextView android:id="@+id/latest_notification" android:layout_width="fill_parent" android:layout_height="20dp" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:freezesText="true" android:marqueeRepeatLimit="marquee_forever" android:paddingLeft="15dip" android:paddingRight="15dip" android:scrollHorizontally="true" android:singleLine="true" />

和片段

        mLatestNotification = (TextView) view
            .findViewById(R.id.latest_notification);
    mLatestNotification.setSelected(true);
    mLatestNotification
            .setText("Scrollable textScrollable textScrollable textScrollable textScrollable text Scrollable text");

现在我的问题是,如果我将小文本分配给TextView,那么选框功能不起作用。有没有办法我可以为小文本应用选框?

谢谢

2 个答案:

答案 0 :(得分:0)

请使用此代码我已从我的项目中抓取它

 <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:lines="1"
    android:textSize="50sp"
    android:singleLine="true"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
    android:textColor="#757575" />

答案 1 :(得分:0)

试试这个,

 <TextView
      android:id="@+id/text"
      android:layout_width="100dp"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:ellipsize="marquee"
      android:marqueeRepeatLimit="marquee_forever"
      android:singleLine="true"
      android:text="TextView TextView TextView TextView TextView TextView TextView TextView TextView TextView"
      android:textAppearance="?android:attr/textAppearanceSmall" />

仅在文字大小较大时才有效。