Android imitation QQ space bottom Menu Sample code _android

Source: Internet
Author: User
Previously seen on the Internet Android imitation QQ space at the bottom of the menu demo, found that the demo has a lot of bugs, layout with a lot of mysterious numbers. So studied the QQ space bottom menu realization, Oneself wrote a, for everybody reference. The effect is shown in the following illustration:

1, the implementation of the principle is very simple, the bottom menu is a horizontal distribution of the LinearLayout, which is also five linearlayout, their layout_weight are 1, meaning that the bottom of the menu's child control will screen width on average divided into 5 parts. Five linearlayout except the middle one, the rest are placed in the inside ImageView and TextView (in the middle of the first empty, do not put anything in the back to put the chassis and the plus sign).
2, the middle of the plus and the chassis is implemented with Framlayout, now the bottom center position to place the chassis, and then placed in the same position plus, it was done.
3, set the plus touch event, the window is implemented with Popupwindow, and then replace the picture of the plus sign to multiplication. The code looks like this:
Buttommenuactivity.java:
Copy Code code as follows:

Package com.shamoo.qqbuttommenu;
Import COM.SHAMOO.QQBUTTOMMENU.R;
Import android.app.TabActivity;
Import Android.content.Context;
Import android.content.Intent;
Import Android.graphics.Color;
Import android.graphics.drawable.BitmapDrawable;
Import Android.os.Bundle;
Import android.view.Gravity;
Import Android.view.LayoutInflater;
Import android.view.MotionEvent;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.View.OnTouchListener;
Import Android.view.WindowManager;
Import Android.widget.AbsListView;
Import Android.widget.FrameLayout;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
Import Android.widget.PopupWindow;
Import Android.widget.PopupWindow.OnDismissListener;
Import Android.widget.RadioButton;
Import Android.widget.TabHost;
public class Buttommenuactivity extends Tabactivity {
Framelayout Fmpan;
Tabhost Tabhost;
ImageView image;
Framelayout FM;
Layoutinflater Inflater;
Private RadioButton tab_home, Tab_second;
Popupwindow popup;

public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.tab);
Initview ();
Fm.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
Image.setimageresource (R.drawable.toolbar_plusback);
ShowWindow (Fmpan);
}
});
}
private void Initview () {
Inflater = (layoutinflater) this.getsystemservice (Context.layout_inflater_service);
Fmpan = (framelayout) Findviewbyid (R.ID.TAB1);
fm = (framelayout) Findviewbyid (R.ID.BTN_CK);
Image = (ImageView) Findviewbyid (r.id.image1);
}

private void ShowWindow (View parent) {
if (popup = null) {
Layoutinflater Layoutinflater = (layoutinflater) getsystemservice (Context.layout_inflater_service);
View view = Layoutinflater.inflate (R.layout.write_tab, NULL);
Create a Popuwidow object
Popup = new Popupwindow (view, linearlayout.layoutparams.match_parent,320);
Set focus on the bounce window
Popup.setfocusable (TRUE);
Settings allow the outside click to disappear
Popup.setoutsidetouchable (TRUE);
Set up the window to disappear event monitor
Popup.setondismisslistener (New Ondismisslistener () {
public void Ondismiss () {
TODO auto-generated Method Stub
Image.setimageresource (R.drawable.toolbar_plus);
}
});
This is to click "Back" to make it disappear, and it doesn't affect your background.
Popup.setbackgrounddrawable (New bitmapdrawable ());
Popup.settouchinterceptor (New Ontouchlistener () {
public Boolean Ontouch (view view, Motionevent event) {
if (event.getaction () = = Motionevent.action_outside) {
Popup.dismiss ();
Image.setimageresource (R.drawable.toolbar_plus);
return true;
}
return false;
}
});
}
if (!popup.isshowing ()) {
Popup.showasdropdown (parent, gravity.center, 0);
}
}
}

Tab.xml:
Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<tabhost xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@android: Id/tabhost"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<framelayout
Android:id= "@+id/l1"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<framelayout
Android:id= "@android: Id/tabcontent"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
/>
<tabwidget
Android:id= "@android: Id/tabs"
Android:layout_width= "Fill_parent"
android:layout_height= "10.0px"
android:visibility= "Gone"/>
<relativelayout
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<include
Android:layout_alignparentbottom= "true"
Android:id= "@+id/tab1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Layout = "@layout/test"/>
</RelativeLayout>
</FrameLayout>
</TabHost>

Test.xml:
Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:background= "@drawable/TOOLBAR_BG" >
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_gravity= "Bottom"
Android:gravity= "Center_horizontal"
android:orientation= "Horizontal" >
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
android:layout_weight= "1" >
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Top|center"
android:src= "@drawable/tab_timefeed_opacity"
android:visibility= "Visible"/>
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Bottom|center"
android:text= "Buddy News"
Android:textsize= "10.0dip"
android:visibility= "Visible"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
android:layout_weight= "1" >
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Top|center"
android:src= "@drawable/tab_feedback_opacity"
android:visibility= "Visible"/>
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Bottom|center"
Android:text= "Related to Me"
Android:textsize= "10.0dip"
android:visibility= "Visible"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
android:layout_weight= "1"/>
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
android:layout_weight= "1" >
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Top|center"
android:src= "@drawable/tab_myzone_opacity"
android:visibility= "Visible"/>
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Bottom|center"
android:text= "Home"
Android:textsize= "10.0dip"
android:visibility= "Visible"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
android:layout_weight= "1" >
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Top|center"
android:src= "@drawable/tab_applist_opacity"
android:visibility= "Visible"/>
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Bottom|center"
android:text= "Application"
Android:textsize= "10.0dip"
android:visibility= "Visible"/>
</LinearLayout>
</LinearLayout>
<framelayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Center_horizontal"
android:layout_weight= "1" >
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
android:src= "@drawable/toolbar_write_bg"/>
</FrameLayout>
<framelayout
Android:id= "@+id/btn_ck"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
android:layout_weight= "1" >
<imageview
Android:id= "@+id/image1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
android:layout_margintop= "2.0dip"
android:src= "@drawable/toolbar_plus"/>
</FrameLayout>
</FrameLayout>

This demo just like to play, may be written in some places is not standardized. If there is any problem, I hope you can point out, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.