ugly fragment transition to surfaceview with overlay

狂风中的少年 提交于 2019-12-29 08:56:31

问题


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>

回答1:


If you are using a SurfaceView make the background transparent.

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

This worked for me, flickering is gone.



来源:https://stackoverflow.com/questions/14925060/ugly-fragment-transition-to-surfaceview-with-overlay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!