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

时间:2016-07-27 10:45:45

标签: java android xml

在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()));
        }
    };

提前致谢。

2 个答案:

答案 0 :(得分:1)

尝试使用LinearLayout包装TextView1。

答案 1 :(得分:0)

检查Activity类TextView对象及其赋值id。