丑陋片段过渡到surfaceview与覆盖 [英] ugly fragment transition to surfaceview with overlay

查看:172
本文介绍了丑陋片段过渡到surfaceview与覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的片段之一,吸引与覆盖按钮和文本从表面上看地图。

其他大部分碎片都列出。我的问题是,在地图和另一个片段之间的过渡期间,难看黑色矩形瞬间出现在地图视图中,其中的文字和按钮次放置。这出现在一个过渡回到地图更加明显,尽管它发生在两个方向上。我使用的是滑动左/滑动右侧的动画它在所有其他方面很好地工作。我已经尝试过其他的动画和没有动画。设置文本和按钮不可见之前的过渡也没有帮助,因为意见是仍然存在的覆盖。

如果任何人有任何想法如何干净片段转换可能实现那将是非常美联社preciated。我现在用的是支持片段经理。

下面是我的code(也有相当多的文字,比我在下面的按钮):

布局的xml文件:

 < XML版本=1.0编码=UTF-8&GT?;


<的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / mapframeview
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
 >


< com.mypackage.MapView
    机器人:ID =@ + ID / maptileview
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
< /com.mypackage.MapView>

< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / mapoverlay
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>

   <的TextView
    机器人:ID =@ + ID / titletext
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_centerHorizo​​ntal =真
    机器人:layout_alignParentTop =真
    机器人:paddingTop =10dp
    机器人:文字颜色=#FFFFFF
    机器人:TEXTSIZE =24dp
    机器人:TEXTSTYLE =黑体/>

    <的ImageButton
    机器人:ID =@ + ID / bookButton
    机器人:的onClick =onClickBookButton
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentTop =真
    机器人:layout_alignParentRight =真
    机器人:paddingTop =15dp
    机器人:paddingRight =15dp
    机器人:背景=@机器人:彩色/透明
    机器人:SRC =@可绘制/ bookbutton>
    < / ImageButton的>

  < / RelativeLayout的>

 < /的FrameLayout>
 

片段过渡code:

 私人无效startNextFragment(片段newFragment,弦乐片段标记){

FragmentManager fragmentManager = getSupportFragmentManager();

    FragmentTransaction交易=
            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(空);

    //提交事务
    器transaction.commit();
}
 

动画XMLS:

 < XML版本=1.0编码=UTF-8&GT?;
<! - 
/ * //device/apps/common/res/anim/slide_in_right.xml * /
 - >

<设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<翻译机器人:fromXDelta =50%P机器人:toXDelta =0
        机器人:时间=@安卓整数/ config_mediumAnimTime/>
<阿尔法机器人:fromAlpha =0.0的Andr​​oid版本:toAlpha =1.0
        机器人:时间=@安卓整数/ config_mediumAnimTime/>
< /集>

< XML版本=1.0编码=UTF-8&GT?;
<! - 
/ * //device/apps/common/res/anim/slide_out_left.xml*/
 - >

<设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<翻译机器人:fromXDelta =0安卓toXDelta = -  50%P
        机器人:时间=@安卓整数/ config_mediumAnimTime/>
<阿尔法机器人:fromAlpha =1.0的Andr​​oid版本:toAlpha =0.0
        机器人:时间=@安卓整数/ config_mediumAnimTime/>
< /集>
 

解决方案

如果您使用的是SurfaceView使背景透明。

 安卓背景=@机器人:彩色/透明
 

这工作对我来说,闪烁也没有了。

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>

解决方案

If you are using a SurfaceView make the background transparent.

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

This worked for me, flickering is gone.

这篇关于丑陋片段过渡到surfaceview与覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆