问题描述
我想在 android 地图应用程序(下图)中实现类似 Places 的弹出/覆盖屏幕(我更感兴趣的是如何将该屏幕放置在屏幕的右侧/左侧).我可以创建一个活动并使用对话框主题,这主要解决了我的问题,但它位于屏幕的中心.有人有更好的想法,我如何创建一个弹出/覆盖屏幕,例如非地图应用程序中的位置并放置在屏幕的顶部/右侧?我猜他们是通过地图叠加来做到的.
I would like to achieve a popup/overlay screen like Places (i`m more interested how can i place that screen for example in the right/left side of the screen ) in the android maps application (image below). I can create an activity and use the Dialog theme, this mostly resolve my problem, but it placed center in the screen. Somebody have any better idea how i can create a popup/overlay screen like the places in a non-map application and place to top/right of the screen ?. My guess they did it with map overlays.
推荐答案
好吧,这就是我所做的...我使用 FrameLayout 覆盖了一个 LinearLayout,我可以在其中填充一个 View.这是我的代码的摘录:
well, here's what I did... I used a FrameLayout to overlay a LinearLayout where I can fill it with a View. Here's an excerpt of my code:
XML:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<fragment class="com.some.location.to.fragment"
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/overlay_pane"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:background="@color/transparent">
</LinearLayout>
</FrameLayout>
然后在我的某个按钮上的代码中,我只需将一个视图(在您的情况下,它可以只是对话框的内容)添加到 overlay_pane 线性布局.
Then in my code on some button, I would just add a View (in your case it can just be the dialog's contents) to the overlay_pane LinearLayout.
Java 示例:
ViewGroup container = findViewById(R.id.overlay_pane);
container.setVisibility(View.VISIBLE);
container.addView(some_view_you_inflated);
但是这个膨胀的视图将具有以下背景:@drawable/dialog_full_holo_light 用于像蜂窝样式这样的漂亮边框效果.
But this inflated view would have the following background: @drawable/dialog_full_holo_light for a nice border effect like the Honeycomb style.
您可以在您的 SDK 中的以下文件夹中找到背景可绘制对象
You can find the background drawable in your SDK in the following folder
your_SDK_dir/platforms/android-12/data/res/drawable-hdpi/dialog_full_holo_light.9.png
your_SDK_dir/platforms/android-12/data/res/drawable-hdpi/dialog_full_holo_light.9.png
所以只要把它复制到你的drawables中.
So just copy that into your drawables.
注意:您也可以使用 dialog_full_holo_dark 或任何自定义背景来获得相同的效果.
Note: that you can also use the dialog_full_holo_dark or any custom background for the same effect.
希望对您有所帮助 :) 如果我不清楚,请告诉我
I hope that helps :) Let me know if I was unclear at any point
注意:您可以仅使用带有 match_parent 的 LinearLayout,而不是使用片段,同时为 layout_width 和 layout_height.然后你会用背景"用户界面填充那个 LinearLayout(在问题的例子中..那将是地图)
Note: Instead of using a fragment, you could merely use a LinearLayout with match_parent for both layout_width and layout_height. And then you would fill that LinearLayout with the "background" UI (in the question's example.. that would be the map)
这篇关于android蜂窝中的弹出/覆盖屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!