如何在Activity中添加浮动视图

时间:2011-01-26 19:35:20

标签: java android view custom-view

我构建了一个包含一些图标的SideBar菜单,当点击其中一个图标时,我需要在其中弹出一个视图,其中包含一个View。

我的问题是如何将此视图添加到任何不在栏中的视图的顶部。

为了澄清,这是我在屏幕上显示SideBar的布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="match_parent"
 android:layout_height="match_parent">
 <ImageView android:id="@+id/image01" android:layout_width="wrap_content"
  android:layout_height="wrap_content" android:scaleType="fitXY" />
 <com.view.SideBarView android:id="@+id/sideBar"
  android:layout_width="40px" android:layout_height="match_parent"
  layout_toLeftOf="@id/image01" />
</RelativeLayout>

我需要点击栏上的图标弹出左侧的图像,并在气球内部有一个视图并获得一些用户输入。

如果不是太多,我需要在该浮动视图的图标旁边画一个箭头。

有办法吗?

2 个答案:

答案 0 :(得分:1)

搜索后我发现了怎么做,我可以使用AbsoluteLayout(但我不喜欢它),所以我发现了我的第二个选项,使用PopupWindow将我的内容显示为浮动视图。

这很有效。

答案 1 :(得分:0)

@Marcos如果你所看到的只是浮动视图,你可以使用RelativeLayout,FrameLayout或AbsoluteLayout,如post "Creating Floating Views in Android"所述。