Facebook 风格的弹出窗口如何操作?

发布于 2024-12-23 18:56:03 字数 1288 浏览 1 评论 0原文

我只能假设 Facebook Android 应用程序有一个非常酷的 PopupWindow()。我真的非常非常纠结于布局。知道他们是如何实现 popup.xml 的吗?

我尝试过嵌套几个 LinearLayout。它们的边框看起来像一个 9 块可绘制的。这可能吗?

<?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 好友请求弹出窗口

The Facebook Android app has a very cool, I can only assume, PopupWindow(). I really, really struggle with layouts. Any idea how they implemented the popup.xml?

I've tried nesting a couple of LinearLayouts. Their border looks like a 9-patch drawable. Is that even possible?

<?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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

も星光 2024-12-30 18:56:03

您在给出 iOS 示例时遇到了 Android 问题。 Facebook 应用程序使用 iOS 本机视图,您可以使用 Web 视图执行类似的操作 Bootstrap from Twitter

看看他们的 Popovers

You have an Android question while giving an iOS example. The Facebook app uses an iOS native view, you may do something similar using a web view with Bootstrap from Twitter.

Take a look at their Popovers.

も星光 2024-12-30 18:56:03

我正在尝试做同样的事情,并且我认为我已经能够对其进行逆向工程。第一个任务是确定他们使用的对象类型(我认为这是一个自定义对话框)。好的,然后尝试一下定位和其他方面,然后就可以了。我不确定 9 补丁方面,但从带有布局集的自定义对话框开始,然后配置以下选项

//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();

I am trying to do the same thing, and I think I have been able to revers engineer it. First task was identifying what kind of object they were using (I think it is a custom dialog). OK then just play around with positioning and other aspects and bang there ya go. I am not sure about the 9-patch aspect but start with a custom dialog with your layout set and then configure the following options

//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();
初见 2024-12-30 18:56:03

我通过为列表 xml 的背景提供一个 9 补丁图像并将其包含到需要的主 xml 中来实现此目的,然后在填充列表后,我在需要时切换可见性...还覆盖了 onbackpressed 以便制作列表如果它可见并且不退出应用程序,则消失...

I implemented this by giving the background of the list xml a 9-patch image and including it into the main xml where was needed and then after populating the list I toggled the visibility when needed... Also overrided onbackpressed in order to make the list gone if it was visible and not exit the application...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文