4

My app one of the fragments draws a map in a surface view with an overlay for buttons and text.

Most of the other fragments are lists. My problem is that during the transition between the map and another fragment, ugly black rectangles momentarily appear in the map view where the text and button views are placed. This appears more pronounced on a transition back to the map, although it does happen in both directions. I am using a slide-left/slide-right animation which works nicely in all other respects. I've tried other animations and no animation. Setting the text and buttons invisible before the transition also doesn't help, since the views are still there in the overlay.

If anyone has any ideas how a clean fragment transition might be achieved it would be very much appreciated. I am using the support fragment manager.

Here is my code (there are considerably more text and buttons than I show below):

layout xml file:

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapframeview"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >


<com.mypackage.MapView 
    android:id="@+id/maptileview"  
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
</com.mypackage.MapView>

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapoverlay"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >

   <TextView
    android:id="@+id/titletext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:paddingTop="10dp"
    android:textColor="#FFFFFF"
    android:textSize="24dp"
    android:textStyle="bold" />

    <ImageButton
    android:id="@+id/bookButton"
    android:onClick="onClickBookButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:paddingTop="15dp"
    android:paddingRight="15dp"
    android:background="@android:color/transparent"
    android:src="@drawable/bookbutton">
    </ImageButton>

  </RelativeLayout>

 </FrameLayout>        

fragment transition code:

 private void startNextFragment(Fragment newFragment, String fragment tag) {

FragmentManager fragmentManager = getSupportFragmentManager();

    FragmentTransaction transaction = 
            fragmentManager.beginTransaction();

    transaction.setCustomAnimations(R.layout.slideinright,
                                        R.layout.slideoutleft,  
                                        R.layout.slideinleft, 
                                        R.layout.slideoutright);

    transaction.replace(R.id.fragment_container, newFragment, fragmentTag);
    transaction.addToBackStack(null);

    // Commit the transaction
    transaction.commit();
}

animation xmls:

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/slide_in_right.xml */
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="0"
        android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/slide_out_left.xml*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-50%p"
        android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>
Chris Fawcett
  • 161
  • 3
  • 11
  • Possible duplicate of http://stackoverflow.com/questions/14419521/moving-mapfragment-surfaceview-causes-black-background-flickering – Ben Max Rubinstein Feb 17 '13 at 19:27
  • Thanks - this may well be a related problem but I don't think it's a duplicate because the problem relates to the overlay. Without the overlay the transition is clean. And we aren't using Google Maps. – Chris Fawcett Feb 17 '13 at 19:38
  • That may all be true, but animated effects involving `SurfaceView` have a long history of problems. Consider using `TextureView`, if you are only supporting API Level 11+, as `TextureView` is supposed to work better for animations. – CommonsWare Feb 17 '13 at 19:43
  • We have to support Gingerbread to that is not an option. Besides, we need a SurfaceView for the full map functionality – Chris Fawcett Feb 17 '13 at 19:48

1 Answers1

3

If you are using a SurfaceView make the background transparent.

android:background="@android:color/transparent"

This worked for me, flickering is gone.

StarDust
  • 846
  • 1
  • 13
  • 26