Textview marquee programmatically

前端 未结 2 792
梦如初夏
梦如初夏 2021-01-13 23:58

Trying to populate an textview(s) from an array. I managed to get the desired effect via XML via the code below



        
相关标签:
2条回答
  • 2021-01-14 00:36

    Try this.

    final RelativeLayout relativeLayout = new RelativeLayout(this);
    final RelativeLayout relativeLayoutbotombar = new RelativeLayout(this);
    textView = new TextView(this);
    textView.setId(1);
    
    RelativeLayout.LayoutParams relativlayparamter = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT,
                        RelativeLayout.LayoutParams.MATCH_PARENT);
    
            RelativeLayout.LayoutParams relativlaybottombar = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            relativeLayoutbotombar.setLayoutParams(relativlaybottombar);
    
    
            textView.setText("text text text text text, with a long ");
            textView.setEllipsize(TruncateAt.MARQUEE);
            textView.setSelected(true);
            textView.setSingleLine(true);
    
    
            relativeLayout.addView(relativeLayoutbotombar);
            relativeLayoutbotombar.addView(textView);
            setContentView(relativeLayout, relativlayparamter);
    

    Another option:

    TextView textView = (TextView) this.findViewById(R.id.xxx);  
    textView.setEllipsize(TruncateAt.MARQUEE);
    textView.setText("Text text text text");
    textView.setSelected(true);
    textView.setSingleLine(true);
    
    0 讨论(0)
  • 2021-01-14 00:40

    Try this.. It work

    TextView testing = (TextView) this.findViewById(R.id.testing);
    testing.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    testing.setMarqueeRepeatLimit(-1);
    testing.setSingleLine(true);
    testing.setSelected(true);
    
    0 讨论(0)
提交回复
热议问题