Finished using a workaround that uses TextSwitcher, which is automatically replaced with the remaining substring every x seconds.
Here is the corresponding xml definition from the layout
<TextSwitcher android:id="@+id/slideshow_description" android:textSize="@dimen/description_font_size" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/slideshow_description_anim1" android:textSize="@dimen/description_font_size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLines="2" android:textColor="@color/white" android:singleLine="false"/> <TextView android:id="@+id/slideshow_description_anim2" android:textSize="@dimen/description_font_size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLines="2" android:textColor="@color/white" android:singleLine="false"/> </TextSwitcher>
Here I add the transition animation to the TextSwitcher (in the adapter's getView method)
final TextSwitcher slideshowDescription = (TextSwitcher)slideshowView.findViewById(R.id.slideshow_description); Animation outAnim = AnimationUtils.loadAnimation(context, R.anim.slide_out_down); Animation inAnim = AnimationUtils.loadAnimation(context, R.anim.slide_in_up); slideshowDescription.setInAnimation(inAnim); slideshowDescription.setOutAnimation(outAnim);
Here's how I change the description part
private void updateScrollingDescription(SlideshowPhoto currentSlideshowPhoto, TextSwitcher switcherDescription){ String description = currentSlideshowPhoto.getDescription(); TextView descriptionView = ((TextView)switcherDescription.getCurrentView());
And finally, here I set up a timer that forces it to update every 3.5 seconds.
public void setUpScrollingOfDescription(){ final CustomGallery gallery = (CustomGallery) findViewById(R.id.gallery); //use the same timer. Cancel if running if(timerDescriptionScrolling!=null){ timerDescriptionScrolling.cancel(); } timerDescriptionScrolling = new Timer("TextScrolling"); final Activity activity = this; long msBetweenSwaps=3500; //schedule this to timerDescriptionScrolling.scheduleAtFixedRate( new TimerTask() { int i=0; public void run() { activity.runOnUiThread(new Runnable() { public void run() { SlideshowPhoto currentSlideshowPhoto = (SlideshowPhoto)imageAdapter.getItem(gallery.getSelectedItemPosition()); View currentRootView = gallery.getSelectedView(); TextSwitcher switcherDescription = (TextSwitcher)currentRootView.findViewById(R.id.slideshow_description); updateScrollingDescription(currentSlideshowPhoto,switcherDescription); //this is the max times we will swap (to make sure we don't create an infinite timer by mistake if(i>30){ timerDescriptionScrolling.cancel(); } i++; } }); } }, msBetweenSwaps, msBetweenSwaps); }
Finally, I can leave this problem alone :)
dparnas
source share