2010-04-07 102 views
0

:请参考网址 http://docs.google.com/Doc?docid=0AQhgDtGvE2HgZGZ6cmtua185M2RneG5nYmNm&hl=en显示弹出图片点击

我的查询给出的形象,我怎么能显示与圆形按钮和表行的消息时,我点击圆形按钮与问号。

我知道,我必须使用监听器?按钮,但是我应该在听众中完全做什么,这样当我点击时,它会显示这些警报(图像),当我再次单击时,它会消失。

对于此用户界面,我使用了此处建议的相对布局 - Aligning components at desired positions - 它对我来说非常合适。

那么,我需要完全改变我的基础布局来完成这个吗?

回答

2

您可以使用FrameLayout作为您的UI布局的基础,然后添加一个ImageView叠加层。例如:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/MainFrame" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <!-- Put your normal layout stuff here --> 

</FrameLayout> 

然后在你的代码,你可以创建ImageView并将其添加到MainFrame,它会覆盖你的用户界面,像这样:

FrameLayout mainFrame = (FrameLayout)findViewById(R.id.MainFrame); 
ImageView overlay = new ImageView(this); 
overlay.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.overlay)); 
mainFrame.addView(overlay); 

后来的后来,你可以拨打:

mainFrame.removeView(overlay); 

让它消失。

+0

用过的方式,但我得到了java.lang.IllegalStateException:指定的孩子已经有一个家长。您必须先调用孩子父母的removeView()... – 2012-06-29 10:25:42