繁体   English   中英

如果在另一个TextView中更改了文本,则TextView文本动画将重新启动

[英]TextView text animation is restarted if the text is changed in another TextView

在TextView1中,文本动画从右到左运行,在TextView2中,文本不断变化。 问题是,当我在文本动画TextView1中执行TextView2.setText(“ ...”)时,重新启动了。 是否可以防止动画重新启动?

XML代码TextView1:

<TextView
android:id="@+id/artistAlbum"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingTop="2dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="text text text text text text text"
android:textSize="14sp" />

Java代码初始化TextView1:

final TextView textView1 = (TextView) rootView.findViewById(R.id.textView1);
textView1.setSelected(true);

XML代码TextView2:

    <TextView
    android:id="@+id/seekSongDuration"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:clickable="true"
    android:paddingBottom="12dp"
    android:paddingEnd="2dp"
    android:paddingStart="10dp"
    android:paddingTop="12dp"
    android:text="0%"
    android:textSize="20sp" />

XML代码:

    <TextView
        android:id="@+id/fullSongDuration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:background="@color/background"
        android:clickable="true"
        android:paddingBottom="12dp"
        android:paddingEnd="10dp"
        android:paddingStart="2dp"
        android:paddingTop="12dp"
        android:text="3:15"
        android:textSize="20sp" />

    <org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
        android:id="@+id/seekDuration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@id/seekSongDuration"
        android:layout_toEndOf="@id/seekSongDuration"
        android:layout_toStartOf="@id/fullSongDuration"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        app:dsb_trackHeight="3dp" />

    <com.andexert.library.RippleView
        android:id="@id/butPlayPause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/seekSongDuration"
        android:layout_centerHorizontal="true"
        android:background="@color/background"
        app:rv_alpha="100"
        app:rv_centered="true"
        app:rv_color="@android:color/white"
        app:rv_framerate="15"
        app:rv_rippleDuration="300">

        <ImageView
            android:id="@+id/imgPlayPause"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/ic_play_circle_outline_black_48dp" />

    </com.andexert.library.RippleView>

    <com.andexert.library.RippleView
        android:id="@+id/butShufle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/seekSongDuration"
        android:layout_alignTop="@id/butPlayPause"
        android:background="@color/background"
        app:rv_alpha="150"
        app:rv_color="@android:color/white"
        app:rv_framerate="15"
        app:rv_rippleDuration="300">

        <ImageView
            android:id="@+id/imgShufle"
            android:layout_width="50dp"
            android:layout_height="60dp"
            android:layout_centerInParent="true"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"
            android:src="@drawable/ic_shuffle_black_36dp" />

    </com.andexert.library.RippleView>

    <com.andexert.library.RippleView
        android:id="@+id/butPreviosSong"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/seekSongDuration"
        android:layout_alignTop="@id/butPlayPause"
        android:layout_toEndOf="@id/butShufle"
        android:layout_toStartOf="@id/butPlayPause"
        android:background="@color/background"
        app:rv_alpha="100"
        app:rv_color="@android:color/white"
        app:rv_framerate="20"
        app:rv_rippleDuration="300"
        app:rv_type="rectangle">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_centerInParent="true"
            android:src="@drawable/ic_fast_rewind_black_48dp" />
    </com.andexert.library.RippleView>

    <com.andexert.library.RippleView
        android:id="@+id/butLooping"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/seekSongDuration"
        android:layout_alignParentEnd="true"
        android:layout_alignTop="@id/butPlayPause"
        android:background="@color/background"
        app:rv_alpha="150"
        app:rv_color="@android:color/white"
        app:rv_framerate="20"
        app:rv_rippleDuration="300">

        <ImageView
            android:id="@+id/imgLoopReaped"
            android:layout_width="50dp"
            android:layout_height="60dp"
            android:layout_centerInParent="true"
            android:paddingLeft="7dp"
            android:paddingRight="7dp"
            android:src="@drawable/ic_repeat_black_36dp" />

    </com.andexert.library.RippleView>

    <com.andexert.library.RippleView
        android:id="@+id/butNextSong"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/seekSongDuration"
        android:layout_alignTop="@+id/butPlayPause"
        android:layout_toEndOf="@id/butPlayPause"
        android:layout_toStartOf="@id/butLooping"
        android:background="@color/background"
        app:rv_alpha="100"
        app:rv_color="@android:color/white"
        app:rv_framerate="20"
        app:rv_rippleDuration="300"
        app:rv_type="rectangle">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_centerInParent="true"
            android:src="@drawable/ic_fast_forward_black_48dp" />
    </com.andexert.library.RippleView>

    <RelativeLayout
        android:id="@id/currentSongLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_above="@+id/butPlayPause"
        android:background="@color/backgroundCurrentTrack"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true">


        <com.andexert.library.RippleView
            android:id="@+id/butSettingCurrentSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            app:rv_alpha="100"
            app:rv_centered="true"
            app:rv_color="@android:color/black"
            app:rv_framerate="15"
            app:rv_rippleDuration="300">

            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:padding="8dp"
                android:src="@drawable/ic_more_circle_vert_black_36dp" />

        </com.andexert.library.RippleView>

        <ImageView
            android:id="@+id/iconCurrentPlaylist"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:padding="5dp"
            android:src="@drawable/ic_playlist_play_black_36dp" />

        <TextView
            android:id="@+id/txtNumberSongs"
            android:layout_width="wrap_content"
            android:layout_height="23dp"
            android:layout_marginBottom="3dp"
            android:layout_marginTop="3dp"
            android:layout_toEndOf="@id/iconCurrentPlaylist"
            android:background="@drawable/shape_ellipse"
            android:paddingEnd="6dp"
            android:paddingStart="6dp"
            android:paddingTop="3dp"
            android:text="1/1"
            android:textAlignment="center"
            android:textColor="@color/grayLite"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/songTitle"
            android:layout_width="wrap_content"
            android:layout_height="26dp"
            android:layout_toEndOf="@id/txtNumberSongs"
            android:layout_toStartOf="@id/butSettingCurrentSong"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:paddingLeft="5dp"
            android:paddingTop="2dp"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Title"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/artistAlbum"
            android:layout_width="wrap_content"
            android:layout_height="24dp"
            android:layout_below="@id/songTitle"
            android:layout_toEndOf="@id/iconCurrentPlaylist"
            android:layout_toStartOf="@id/butSettingCurrentSong"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:paddingTop="2dp"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Artist - Album"
            android:textSize="14sp" />
    </RelativeLayout>

Java代码:

  private TextView songArtistAlbum;
private TextView txtSeek;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
songArtistAlbum = (TextView) rootView.findViewById(R.id.artistAlbum);
        songArtistAlbum.setSelected(true);

txtSeek = (TextView) rootView.findViewById(R.id.seekSongDuration);
...
}
    private DiscreteSeekBar.OnProgressChangeListener onDurationProgressChangeListener = new DiscreteSeekBar.OnProgressChangeListener() {
        @Override
        public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) {
            if (!fromUser) {
                txtSeek.setText(Total.msecTo_MM_SS(seekBar.getProgress()));
            }
        }

        @Override
        public void onStartTrackingTouch(DiscreteSeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(DiscreteSeekBar seekBar) {
            txtSeek.setText(Total.msecTo_MM_SS(seekBar.getProgress()));
        }
    };

提前致谢。

尝试用LinearLayout包装TextView1。

检查Activity类TextView对象及其分配ID。

暂无
暂无

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

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