Marquee not working while using in multiple textviews

前端 未结 3 1094
后悔当初
后悔当初 2020-12-19 22:59

I am using marquee in two different TextViews of my widget.But it is working only either for first or the second TextView when i am trying with different combinations of \"a

相关标签:
3条回答
  • 2020-12-19 23:12

    Alternatively you can also simply select the textViews. That puts them into focused and activates the marquee. Worked for me with text views within a listView.

    0 讨论(0)
  • 2020-12-19 23:14

    I'm pretty sure you can't do what you want. Only focused views can "marquee", and since you cannot have two focused views then it's impossible to do what you want out of the box. However, you can look at the startMarquee() method in the TextView and extend a custom TextView that always marquees.

    0 讨论(0)
  • 2020-12-19 23:20

    In MainActivity.java,

    package com.hardian.samplemarque;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    TextView tvText1,tvText2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvText1 = (TextView)findViewById(R.id.tvText1);
        tvText2 = (TextView)findViewById(R.id.tvText2);
    
        tvText1.setSelected(true);
        tvText2.setSelected(true);
    }
    
    }
    

    In activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >
    
    <TextView
        android:id="@+id/tvText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:scrollHorizontally="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit ="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="1 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" />
    <TextView
        android:id="@+id/tvText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:scrollHorizontally="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit ="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="2 It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)." />
    

    0 讨论(0)
提交回复
热议问题