【问题标题】:Displaying popup images on button click在按钮单击时显示弹出图像
【发布时间】:2012-01-15 08:07:15
【问题描述】:

请参考网址中给出的图片 http://docs.google.com/Doc?docid=0AQhgDtGvE2HgZGZ6cmtua185M2RneG5nYmNm&hl=en

我的问题是,当我点击带问号的圆形按钮时,如何显示与圆形按钮和表格行相对应的消息。

我知道,我必须为 ? button ,但是我应该在监听器中做什么,这样当我点击时,它会显示那些警报(图像),当我再次点击时,它会消失。

对于这个 UI,我使用了这里建议的相对布局 -- Aligning components at desired positions -- 它对我来说非常适合。

那么,我是否需要完全更改我的基本布局才能完成此操作?

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    您可以使用 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);
    

    让它消失。

    【讨论】:

    • 使用了你的方式,但我得到了 java.lang.IllegalStateException: The specified child has a parent。您必须先在孩子的父母上调用 removeView()...
    猜你喜欢
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多