MapFragment样式化的对话引起的TextView是透明的 [英] MapFragment Styled as Dialog causes TextView to be transparent

查看:208
本文介绍了MapFragment样式化的对话引起的TextView是透明的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的设置:

我在构造和显示被作为样式对话框居中活动。这是为了显示层次的内容,不应该在设备上全屏幕。

I'm constructing and displaying Activities that are styled as centered Dialogs. This is to show hierarchical content that shouldn't be full-screen on the device.

的内容的一种类型是一个地图。所以,我已经成功地加载MapFragment到对话框风格FragmentActivity。这个作品真的很好。

One type of content is a map. So i've successfully loaded a MapFragment into a Dialog-styled FragmentActivity. This works really well.

问题是,当我试图将地图上方一个新的TextView(作为自定义标题栏)。问题是TextView的内容似乎变得透明和previous活动的内容出现渗透。

The problem is when I attempt to place a new TextView (acting as a custom title bar) above the map. The issue is that the TextView's content seems to become transparent and the previous Activity's content bleeds through.

完全相同的外观设计的作品就好在地图的活动使地图全屏显示。问题是,只有当我试图使地图自定义大小(也有另一种观点认为一起显示)。

The exact same "design" works just fine when the map's activity allows the map to be full screen. The problem is only when i try to make the map a custom size (and also be displayed along with another view).

这里的活动:

public class MapViewActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            requestWindowFeature(Window.FEATURE_NO_TITLE);

            setContentView(R.layout.activity_map_view);

            Window window = this.getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            WindowManager.LayoutParams wmlp = window.getAttributes();
            wmlp.y -= 10;
            window.setAttributes(wmlp);

            Intent i = getIntent();
            String lat = i.getExtras().getString("lat");
            String lng = i.getExtras().getString("lng");
            String title = i.getExtras().getString("title");
            String snippet = i.getExtras().getString("address");

            TextView tv = (TextView)this.findViewById(R.id.mapTitle);
            tv.setText(title);

            SupportMapFragment mf = (SupportMapFragment)this.getSupportFragmentManager().findFragmentById(R.id.map);

            MarkerOptions mo = new MarkerOptions();
            mo.position(new LatLng( Double.valueOf(lat), Double.valueOf(lng) ));
            mo.title(title);
            mo.snippet(snippet);

            GoogleMap gm = mf.getMap();

            gm.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng( Double.valueOf(lat), Double.valueOf(lng) ), 14));
            gm.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            gm.setMyLocationEnabled(true);
            gm.addMarker(mo);

    }
}

下面是布局的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="300dp"
    android:layout_height="365dp" 
    tools:context=".MapViewActivity" >

    <TextView 
        android:id="@+id/mapTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:textSize="18sp"
        android:textColor="@color/white"
        android:background="@color/blue"
        android:text="TEST TITLE LABEL"
    >
    </TextView>

    <fragment
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="280dp"
      android:layout_below="@id/mapTitle"
      class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

下面是我定义清单中的活动时使用的样式:

Here's the style that I use when defining the Activity in the manifest:

    <style name="SubViewTheme" parent="android:Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/MainViewAnimation</item>
        <item name="android:windowBackground">@color/white</item>
        <item name="android:background">@null</item>
    </style>

我做的,以显示该活动是使用标准启动 startActivity(I);

和这里的结果的屏幕截图。很抱歉的质量差。这是一个痛苦让我Nexus1的屏幕盖。

And here's a screen cap of the outcome. Sorry for the poor quality. It's a pain to get a screen cap of my Nexus1.

地图对话框的屏幕快照

"screen shot of the map dialog"

在屏幕截图,你会看到地图中的对话的活动。而TextView中正在出现 - TextView的是在地图的右上角的小深蓝色的长方形。然后到搞砸标签左侧我们从previous对话框,通过其中的TextView应该是流血的文字。

In the screen shot you'll see the "dialog" activity with the map. And the TextView IS appearing - the TextView is the small dark-blue rectangle at the top right of the map. then to the left of the messed up label we have the text from the previous dialog bleeding through where the TextView SHOULD be.

有什么明显的是我做错了吗?也许我是新MapFragment支持:)过于雄心勃勃。

Is there anything obvious that I'm doing wrong? Maybe i'm being too ambitious with the new MapFragment support :).

这个项目需要支持回2.3.3,所以我坚持与支持库。

This project requires support back to 2.3.3 so i'm stuck with the support libs.

感谢您的帮助。让我知道如果我在描述什么是没有意义的。

Thanks for any help. Let me know if anything in my description doesn't make sense.

推荐答案

天啊,我不能相信这是我发现....唯一的答案

Oh god I can't believe this is the only answer that I have found....

创建另一个片段上创建做fragmentTransaction隐藏地图片段让这个运行了一段时间(我等待着我的谷歌地图调用/函数返回),然后做一套FT显示这个固定的透明度mapFragment问题。

Create another fragment and on create do a fragmentTransaction to hide your map fragment let this run for a period of time (I waited for my Google Directions calls/functions to return) then do another FT to show the mapFragment this fixed the transparency issue.

在的onCreate

in onCreate

final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.hide(mDirMapFrag);
ft.commit();
getSupportFragmentManager().executePendingTransactions();

//隐藏地图,列表片段显示我的默认。

//Hides the map, list fragment is shown my default.

//在我的方法是从谷歌的方向方法返回,但你可能只是做一个快速的处理程序H =新的处理程序(); h.postDelayed(新的Runnable(){}等。

//in my method which is returned from the google directions methods but you could just do a quick Handler h = new Handler(); h.postDelayed(new Runnable() {} etc.

final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.show(mDirMapFrag);
ft.commit();
getSupportFragmentManager().executePendingTransactions();

有没有人有比这更好的解决办法?

Does anyone have a better solution than this?

这篇关于MapFragment样式化的对话引起的TextView是透明的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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