类似Facebook的弹出框怎么做?

4

Facebook的Android应用程序有一个非常酷的,我只能猜测是PopupWindow()。我真的很难处理布局。您有任何关于他们如何实现popup.xml的想法吗?

我尝试了嵌套几个LinearLayouts。它们的边框看起来像是9-patch drawable。这是否可能?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/outerLinear"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/darkGrey" >

        <TextView
            android:id="@+id/groupTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="some text" />
    <LinearLayout
        android:id="@+id/innerLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="@drawable/white"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

    </LinearLayout>

</LinearLayout>

Facebook Friend Requests Popup


你可以查看这个链接:https://dev59.com/zYTca4cB1Zd3GeqPBvdM#34194097 - Anuj Sharma
3个回答

1

当你给出 iOS 的例子时,你有一个 Android 相关问题。Facebook 应用程序使用 iOS 本地视图,您可以使用 Twitter 的 Bootstrap 中的 Web 视图类似的方法来实现。

看看他们的 Popovers


我进行了快速搜索,但找不到Facebook弹出窗口的Android屏幕截图,但在Android上几乎完全相同。没有使用WebView。 - Bill Mote
如果不是 WebView,我不知道 Android 正在使用什么。 - dimme
4
安卓图标:http://imageshack.us/photo/my-images/9/facebookandroid.png/ 这就是你想要的,对吗? - sebastianf182

0

我通过为列表XML的背景提供9-patch图像并将其包含在需要的主XML中来实现这一点,然后在填充列表后根据需要切换可见性...还覆盖了onbackpressed以使列表消失(如果它是可见的)而不退出应用程序...


0

我正在尝试做同样的事情,我认为我已经成功地进行了反向工程。首先要做的是确定他们使用的是什么类型的对象(我认为这是一个自定义对话框)。然后只需玩弄位置和其他方面,就可以实现目标了。我不确定9-patch方面的内容,但是从一个设置了布局的自定义对话框开始,然后配置以下选项。

//create your dialog
Dialog popup = new Dialog(this);
//remove title bar
popup.requestWindowFeature(Window.FEATURE_NO_TITLE);
//set the layout resource
popup.setContentView(R.layout.custom_dialog);
//can be canceled
popup.setCancelable(true);
//touch outside of dialogue cancels
popup.setCanceledOnTouchOutside(true);
//set background to transparent instead of normal black
popup.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//grab the layout params
WindowManager.LayoutParams lp = popup.getWindow().getAttributes();
//move the popup to desired location
lp.y -= 160/lp.height;
lp.x -= 70/lp.width;
//remove the dim effect
lp.dimAmount = 0;
//set new params
popup.getWindow().setAttributes(lp);
//show the custom dialog
popup.show();

我也没有放弃。我已经阅读了关于具有透明视图背景的浮动活动窗口、自定义对话框的资料,并且目前实际上正在使用一个主题为对话框的活动。我甚至尝试了PopupWindow()但并不成功。今晚我会看看你的实现,因为我目前选择的那个还不完美。 - Bill Mote
好的 @BillMote 祝你好运。我一直在使用它,对我来说效果非常不错。 - MikeIsrael

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接