TextView中没有自定义列表视图内滚动 [英] Textview not scrolling inside custom listview

查看:154
本文介绍了TextView中没有自定义列表视图内滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多具有水平滚动文本列表视图中。结果
我希望我的TextView之一,像跑马灯水平自动滚动
IAM可以设置水平滚动条和滚动触摸它作为

  TVad.setMovementMethod(新ScrollingMovementMethod());

这是我的xml文件

 <?XML版本=1.0编码=UTF-8&GT?;

 <的TextView
    机器人:ID =@ + ID / tvinboxname
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium/><的TextView
    机器人:ID =@ + ID / tvinboxmsg
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID / tvinboxname
    机器人:最大长度=10
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium/><的TextView
    机器人:ID =@ + ID / tvtimeStamp
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentRight =真
    机器人:layout_below =@ + ID / tvinboxmsg
    机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?
    <的TextView
        机器人:ID =@ + ID / tvadmsg
        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / tvtimeStamp
        机器人:ellipsize =金字招牌
        机器人:focusableInTouchMode =真
        安卓的inputType =TEXT
        机器人:可聚焦=真
        机器人:marqueeRepeatLimit =marquee_forever
        机器人:行=1
        机器人:scrollHorizo​​ntally =真
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:文字颜色=#330066/>

在我getview方法

  // @覆盖
        公共查看getView(最终诠释的立场,观点convertView,
                父母的ViewGroup){
            convertView = inflater.inflate(R.layout.inboxtextviews,NULL);
            Tvname =(TextView中)convertView.findViewById(R.id.tvinboxname);
            Tvname.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(位置)
                    .getname());
            TVmsg =(TextView中)convertView.findViewById(R.id.tvinboxmsg);
            TVmsg.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(位置)
                    .getmessage());
            TVtimeStamp =(TextView中)convertView.findViewById(R.id.tvtimeStamp);
            TVtimeStamp.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(
                    位置).getTimeStamp());            TVad =(TextView中)convertView.findViewById(R.id.tvadmsg);            TVad.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(
                    位置).getAd());            TVad.setSelected(真);
);
            返回convertView;
        }

我搜索了很多关于这个计算器中,不能够显示滚动文本。


解决方案

使用自定义类,如下所示以及

 公共类MyTextView扩展的TextView { 公共MyTextView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,defStyle);
        在里面();
        旋转();
    }    公共MyTextView(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
        在里面();
        旋转();
    }    公共MyTextView(上下文的背景下){
        超级(上下文);
        在里面();
        旋转();
    }    私人无效旋转(){
        // TODO自动生成方法存根
        的setSelected(真);
    }    私人无效的init(){
        如果(!isInEditMode()){        }
    }
  }

像图所示

添加XML文件中的列表视图custome

 <您的包Name.MyTextView
    机器人:layout_marginTop =10dip机器人:ID =@ + ID / tv_parse
    机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:TEXTSIZE =的22px
        机器人:文字颜色=#34A4c5
        机器人:ellipsize =金字招牌
        安卓了maxWidth =220DP
        机器人:fadingEdge =横向
        机器人:marqueeRepeatLimit =marquee_forever
        机器人:scrollHorizo​​ntally =真
        机器人:单线=真
        机器人:layout_marginLeft =10dp
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:layout_marginRight =10dp>< /你的包Name.MyTextView>

I tried a lot for having scrolling text horizontally inside a listview.
i want one of my textview to scroll horizontally automatically like marquee iam able to set horizontal scroll bar and scroll on touching it as

TVad.setMovementMethod(new ScrollingMovementMethod());

This is my xml file

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/tvinboxname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/tvinboxmsg"    
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvinboxname"
    android:maxLength="10"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/tvtimeStamp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/tvinboxmsg"
    android:textAppearance="?android:attr/textAppearanceSmall" />


    <TextView
        android:id="@+id/tvadmsg"
        android:layout_width="wrap_content"

        android:layout_height="wrap_content"
        android:layout_below="@+id/tvtimeStamp"
        android:ellipsize="marquee"
        android:focusableInTouchMode="true"
        android:inputType="text"
        android:focusable="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:lines="1"
        android:scrollHorizontally="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#330066" />

and in my getview method

    // @Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            convertView = inflater.inflate(R.layout.inboxtextviews, null);
            Tvname = (TextView) convertView.findViewById(R.id.tvinboxname);
            Tvname.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(position)
                    .getname());
            TVmsg = (TextView) convertView.findViewById(R.id.tvinboxmsg);
            TVmsg.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(position)
                    .getmessage());
            TVtimeStamp = (TextView) convertView.findViewById(R.id.tvtimeStamp);
            TVtimeStamp.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(
                    position).getTimeStamp());

            TVad= (TextView) convertView.findViewById(R.id.tvadmsg);

            TVad.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(
                    position).getAd());

            TVad.setSelected(true);
);
            return convertView;
        }

i searched a lot on this in stackoverflow and not able to display the scrolling text.

解决方案

Use custom class as shown below and

 public class MyTextView extends TextView{

 public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
        rotate();
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        rotate();
    }

    public MyTextView(Context context) {
        super(context);
        init();
        rotate();
    }

    private void rotate() {
        // TODO Auto-generated method stub
        setSelected(true);
    }

    private void init() {
        if (!isInEditMode()) {

        }
    }


  }

add it in xml file for custome listview like shown below

    <Your Package Name.MyTextView
    android:layout_marginTop="10dip" android:id="@+id/tv_parse"
    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="22px"
        android:textColor="#34A4c5"
        android:ellipsize="marquee"
        android:maxWidth="220dp" 
        android:fadingEdge="horizontal"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"  
        android:singleLine="true"
        android:layout_marginLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_marginRight="10dp"></Your Package Name.MyTextView>

这篇关于TextView中没有自定义列表视图内滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆