4

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

Bill Mote
  • 12,644
  • 7
  • 58
  • 82

3 Answers3

1

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.

dimme
  • 4,393
  • 4
  • 31
  • 51
  • I did a quick search and couldn't find an Android screen capture of the Facebook Popup, but it's almost identical on Android. Not using a WebView. – Bill Mote Jan 04 '12 at 00:07
  • I'm not aware of what Android is using if it's not a WebView. – dimme Jan 04 '12 at 00:19
  • 4
    Android thumb: http://imageshack.us/photo/my-images/9/facebookandroid.png/ This is what you want right? – sebastianf182 Jan 04 '12 at 00:24
0

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

zwebie
  • 2,349
  • 1
  • 27
  • 43
0

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();
MikeIsrael
  • 2,871
  • 2
  • 22
  • 34
  • I didn't give up either. I've read about floating activity windows with transparent view backgrounds, custom dialogs and I'm actually using an activity themed as a dialog at the moment. I even gave the PopupWindow() a go without much success. I'll look at your implementation tonight as the one I've settled on for the moment is not perfect. – Bill Mote Jan 16 '12 at 15:36
  • ok @BillMote good luck. I have been using it, and it worked pretty well for me. – MikeIsrael Jan 16 '12 at 16:38