Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

android - ugly fragment transition to surfaceview with overlay

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are using a SurfaceView make the background transparent.

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

This worked for me, flickering is gone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...