1

我试图使用选框但它不起作用,这是我的代码......有人能看到问题吗?

 <TextView
        android:id="@+id/lblTitle" 

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

        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="15dp"
        android:gravity="center"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:text="Book Title"
        android:textColor="#FFFFFF"
        android:textSize="12dp" />

我在运行时设置了这个 textview 的文本。我使用此链接中的代码 TextView Marquee not working

4

6 回答 6

13

只需在您的活动中这样做,因为您的代码对于简单的 textview marquee 来说是可以的

TextView textview=(TextView)findViewById(R.id.lblTitle);
textview.setSelected(true); 

如果你想在适配器的列表视图中使用选框,而不是检查在列表视图中选框给出的答案

于 2012-06-28T07:37:07.420 回答
4
working on my phone 

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/lblTitle" 

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

            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:gravity="center"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text="Book Title sad ds sdas das asdas das asd asd sad as"
            android:textColor="#FFFFFF"
            android:textSize="12dp" />
    </LinearLayout>

在此处输入图像描述

于 2012-06-28T07:35:19.360 回答
3

此代码为您工作。

<TextView
    android:text="START | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | END"
    android:id="@+id/MarqueeText" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:singleLine="true"
    android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:paddingLeft="15dip" 
    android:paddingRight="15dip" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true">
</TextView>

谢谢。

于 2012-06-28T07:29:59.437 回答
1

此代码有效

<TextView
android:text="A very long book title"
android:id="@+id/book_title" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:singleLine="true"
android:ellipsize="marquee" 
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true" 
android:paddingLeft="15dip" 
android:paddingRight="15dip" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:freezesText="true">
于 2013-09-10T10:10:26.780 回答
1

我遇到了同样的问题。Khan 的回答是对的,但有时 textview.setSelected(true); 当文本视图始终无法获得焦点时不起作用。因此,为了确保 TextView Marquee 正常工作,我不得不使用自定义 TextView。

public class CustomTextView extends TextView {
    public CustomTextView(Context context) {
        super(context);
    }
    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }


    @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 作为布局 .xml 文件中的滚动文本视图,如下所示:

<com.example.myapplication.CustomTextView
            android:id="@+id/tvScrollingMessage"
            android:text="@string/scrolling_message_main_wish_list"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit ="marquee_forever"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollHorizontally="true"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@color/black"
            android:gravity="center"
            android:textColor="@color/white"
            android:textSize="15dp"
            android:freezesText="true"/>

注意:在上面的代码片段中,com.example.myapplication 是一个示例包名,应替换为您自己的包名。

希望这会帮助你。干杯!

于 2016-04-16T10:46:15.383 回答
0

这行代码可以 100% 工作,只需将这些行放在您的 textview xml 代码中,它就会开始工作

 android:singleLine="true" 
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" 
于 2016-10-03T11:49:29.600 回答