2016-07-27 64 views
0

在TextView1中,文本動畫從右向左運行,並且在TextView2中不斷更改文本。問題是,當我在文本動畫TextView1重新啓動時執行TextView2.setText(「...」)。是否有可能阻止重新開始動畫?如果文本在另一個TextView中發生更改,TextView文本動畫將重新啓動

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

在此先感謝。

回答

1

嘗試用LinearLayout包裝TextView1。

+0

它幫助我。但問題是什麼?爲什麼在RelativeLayout動畫中重新啓動,並且在LinearLayout中沒有? – Novah

0

檢查Activity類TextView對象及其賦值id。

+0

有動畫工作的名爲'setSelected(true)'的對象的Java代碼。我不明白問題是什麼。 – Novah

+0

加你java代碼和XML代碼,所以確切檢查有什麼問題 –

+0

我加了java和xml代碼 – Novah

相關問題