Updated my phone on the hundred read software, the above Floating dialog box selection is very good, imitate a bit. Let's take a look at the running effect. Updated my phone on the hundred read software, the above Floating dialog box selection is very good, imitate a bit. Let's take a look at the running effect.
The main principle is to throw a GridView into the dialog, which can be used as a component. The source code is the following dialog box used by Layout:grid_dialog.xml<?xmlversion="1.0"encoding="Utf-8"? ><relativelayoutxmlns:android=""Android:id="@+id/layout_root"Android:layout_width="wrap_content"Android:layout_height="wrap_content"><gridviewandroid:id="@+id/mygridview"Android:numcolumns="3"android:gravity="Center"Android:layout_width="wrap_content"Android:layout_height="wrap_content"android:padding="10DP"android:verticalspacing="20DP"android:horizontalspacing="10DP"Android:stretchmode="ColumnWidth"></GridView></RelativeLayout>items in the dialog list Layout:grid_item.xml<?xmlversion="1.0"encoding="Utf-8"? ><relativelayoutxmlns:android=""Android:id="@+id/relativelayout01"Android:layout_width="fill_parent"Android:layout_height="fill_parent"android:gravity="Center"><imageviewandroid:id="@+id/item_image"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_centerhorizontal="true"/><textviewandroid:id="@+id/item_text"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_below="@id/item_image"Android:layout_centerhorizontal="true"Android:text="@+id/item_text"/></relativelayout>Custom dialog box class: Griddialog.java import java.util.ArrayList; Import Java.util.HashMap; Import java.util.List; Import Java.util.Map; Import android.app.Activity; Import Android.app.Dialog; Import ntent. Context; Import ntent. Intent; Import android.view.Gravity; Import Android.view.View; Import Android.view.Window; Import Android.view.WindowManager.LayoutParams; Import Android.widget.AdapterView; Import Android.widget.AdapterView.OnItemClickListener; Import Android.widget.GridView; Import Android.widget.SimpleAdapter; Import Android.widget.Toast; Publicclass Griddialog extends Dialog {Privatelist<int[]> GridItem =Newarraylist<int[]>(); {Griditem.add (newint[] {r.drawable.edit, R.string. Edit});//picture resources, title, can be set by oneselfGriditem.add (newint[] {r.drawable.delete, R.string. Delete}); Griditem.add (newint[] {r.drawable.favsaddto, R.string. favsaddto}); Griditem.add (newint[] {r.drawable.favs, R.string. favs}); Griditem.add (newint[] {r.drawable.settings, R.string. Settings}); Griditem.add (newint[] {r.drawable.sync, R.string. sync}); Griditem.add (newint[] {r.drawable.save, R.string. Save}); Griditem.add (newint[] {r.drawable.search, R.string. Search}); Griditem.add (newint[] {r.drawable.camera, R.string. camera}); }; PrivateGridView GridView; PublicGriddialog (Context context, Boolean cancelable, Oncancellistener Cancellistener) {Super (context, cance lable, Cancellistener); } PublicGriddialog (Context context,inttheme) {Super (context, theme); } privatevoid Initgrid () {List<map<string, object>> items =NewArraylist<map<string, object>>(); for(int[] item:griditem) {Map<string, object> map =NewHashmap<string, object>(); Map.put ("Image", item[0]); Map.put ("title", GetContext (). getString (item[1])); Items.Add (map); } Simpleadapter Adapter=NewSimpleadapter (GetContext (), Items,//List ContentsR.layout.grid_item,NewString[] {"title","Image"}, newint[] {em_text, em_image}); GridView=(GridView) Findviewbyid (R.id.mygridview); //set data for the GridViewGridview.setadapter (adapter); } PublicGriddialog (Context context) {super (context); Requestwindowfeature (Window.feature_no_title); //Remove the dialog title and put it in front of the Setcontentview or you will get an error.Setcontentview (R.layout.grid_dialog); Setcanceledontouchoutside (true);//Click outside the dialog box to cancel the dialog box displayLayoutparams LP =GetWindow (). GetAttributes (); GetWindow (). SetAttributes (LP); GetWindow (). Addflags (layoutparams.flag_blur_behind);//add Blur effect//sets the transparency of the dialog box transparent (including the contents of the dialog box) Alpha is between 0.0f and 1.0f. 1.0 completely opaque, 0.0f completely transparent//lp.alpha = 0.5f;Lp.dimamount=0.1f;//Set the dialog box to display the darkness, between 0.0f and 1.0f, where I set the 0.0f will appear black screen state, solve. Initgrid ();//Add Table button contents } /** * bind event to specified activity * * @param activity*/publicvoid bindevent (activity activity) {setowneractivity (activity);//) Attach the dialog to an activityGridview.setonitemclicklistener (NewOnitemclicklistener () {publicvoid Onitemclick (Adapterview<?>Parent, View V,intPositionLongID) {Switch(position) {//position starting from 0, the location of the button in the GridViewCase0:Toast.makeText (GetContext (),"Test", Toast.length_short). Show (); Break; } } }); }}
The above code does not implement an active jump. If you want to implement a jump using the following methods:,
Privatevoid Redirect (class<?> cls) { if (getowneractivity (). GetClass ()! = CLS) {////If the dialog is not bound to active then jump Dismiss ();//Close dialog box Intent Intent = new Intent (); Intent.setclass (GetContext (), CLS); GetContext (). StartActivity (intent);//Jump } }
dialog box Call Method:
Publicclass Mainactivity extends Activity {/** Called when the activity is first created.*/@Overridepublicvoid onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Button Button=(Button) Findviewbyid (R.ID.BUTTON01); Button.setonclicklistener (NewButton.onclicklistener () {@Overridepublicvoid OnClick (View arg0) {Griddialog dialog=NewGriddialog (mainactivity. This); Dialog.bindevent (mainactivity. This); Dialog.show (); } }); } }
Android: Implementing a floating selection menu effect