Bill Mote
Bill Mote

Reputation: 12823

Facebook-esque Popup How-to?

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

Upvotes: 4

Views: 1126

Answers (3)

zwebie
zwebie

Reputation: 2348

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

Upvotes: 0

MikeIsrael
MikeIsrael

Reputation: 2889

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

Upvotes: 0

dimme
dimme

Reputation: 4424

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.

Upvotes: 1

Related Questions