MapFragment样式为Dialog导致TextView透明

时间:2013-01-02 17:42:17

标签: android dialog textview android-fragmentactivity mapfragment

以下是设置:

我正在构建和显示被设置为居中对话框的活动。这是为了显示不应在设备上全屏的分层内容。

一种内容是地图。所以我已成功将MapFragment加载到Dialog风格的FragmentActivity中。这非常有效。

问题是当我尝试在地图上方放置一个新的TextView(充当自定义标题栏)时。问题是TextView的内容似乎变得透明,而之前的Activity内容也流畅了。

当地图的活动允许地图全屏时,完全相同的“设计”工作正常。问题是当我尝试使地图成为自定义尺寸(并且还与其他视图一起显示)时。

这是活动:

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>

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

    <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的屏幕上限很痛苦。

screen shot of the map dialog“地图对话框的屏幕截图”

在屏幕截图中,您将看到地图上的“对话框”活动。 TextView IS出现 - TextView是地图右上角的小深蓝色矩形。然后在混乱的标签的左边,我们得到了上一个对话框中的文本,这些文本应该出现在TextView应该的位置。

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

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

感谢您的帮助。如果我的描述中的任何内容都没有意义,请告诉我。

2 个答案:

答案 0 :(得分:2)

将透明视图放在地图上方。

<RelativeLayout
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true" />

<View
    android:id="@+id/MyView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" />

答案 1 :(得分:1)

天哪,我无法相信这是我找到的唯一答案....

创建另一个片段并在创建时执行一个fragmentTransaction隐藏你的地图片段让它运行一段时间(我等待我的Google Directions调用/函数返回)然后再做一个FT来显示mapFragment这个修复了透明度问题。

创建

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

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

//在我的方法中,从google指令方法返回,但你可以做一个快速的Handler h = new Handler(); h.postDelayed(new Runnable(){}等。

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

有没有人有比这更好的解决方案?