简体   繁体   English

在TextView中自动水平滚动的问题

[英]Issue with Automatically horizontal scroll in TextView

I wanted to implement automatically horizontal scroll for the situation if my Text is too long. 如果文本太长,我想针对这种情况自动实现水平滚动。 It worked when the activity is empty without anything focus on. 当活动为空而没有重点关注时,它就起作用了。 But when I tried implement this in an activity with chronometers, it's not working. 但是,当我尝试在带有计时器的活动中实现此功能时,它不起作用。 I tested it out without chronometer it works. 我没有计时码表就可以测试它。 I tried to use setSelected(true) , it's not working also. 我尝试使用setSelected(true) ,它也无法正常工作。 Is there any way to solve this, I need the scrolling function with the chronometer. 有什么办法可以解决这个问题,我需要带计时器的滚动功能。 Any comments and answer would be appreciated. 任何意见和答案将不胜感激。

ScrollTextView.class ScrollTextView.class

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 文字检视

<com.android.app.ScrollingTextView
    android:id="@+id/display_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:paddingLeft="10dp"
    android:paddingTop="10dp"
    android:singleLine="true"
    android:text="Display Message"
    android:textSize="18dp"
    android:textColor="#ffffff"
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusableInTouchMode="true"/>

Add this in your XML 在您的XML中添加

I've figured it out by myself. 我自己弄清楚了。

android:focusable="true" 

& then try again. 然后再试一次。

Edit : 编辑:

i face this problem 我面对这个问题

In my case this is the reason why Textview is not Scrolling is that, 就我而言,这就是Textview不滚动的原因,

i put a listview in above textview so the textview is not scrolling. 我在上面的文本视图中放置一个列表视图,以便该文本视图不滚动。 so itried this one 所以这遍

set listview focusable is false 设置listview focusable为false

listview.setfocusable(false);

then it works the text was scrolling. 然后文字滚动即可。

Try this, it may help you. 试试这个,可能对您有帮助。

 <TextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:onClick="onClick" android:smoothScrollbar="true" android:scrollbars="vertical" android:maxLines="6" android:ellipsize="none" android:scrollHorizontally="false" android:singleLine="false" /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM