To achieve this effect: a turntable with several button distributions next to it. Each button can be clicked:
On the surface, there are 5 buttons, in fact each of the buttons are a large circle, the placement of the position is overlapping. Only the part that is pressed down will have color, the others are transparent.
Look at this layout file and you'll know how it's placed:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "android:backg round= "@drawable/back_ground_yellow" tools:context= "Com.example.circle.mainactivity$placeholderfragment" > <imageview android:id= "@+id/imageview1" android:layout_width= "Wrap_content" Android oid:layout_height= "Wrap_content" android:layout_centerinparent= "true" android:src= "@drawable/picture"/> <imageview android:id= "@+id/imageview2" android:layout_width= "Wrap_con Tent "android:layout_height=" Wrap_content "android:layout_centerinparent=" true "android:src=" @drawab Le/white_picture "/> <com.example.circle.trapezoidimagebutton android:id=" @+id/telId1 "a Ndroid:layout_centerinparent= "true" anDroid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:background= "@drawable/select_ Menu_1 "android:tag=" telId1 "/> <com.example.circle.trapezoidimagebutton android:id = "@+id/telid2" android:layout_centerinparent= "true" android:layout_width= "Wrap_content" android:layou t_height= "Wrap_content" android:background= "@drawable/select_menu_2" android:tag= "TelId12"/> <com.example.circle.trapezoidimagebutton android:id= "@+id/telid3" Android:layout_centerinpare Nt= "true" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:background = "@drawable/select_menu_3" android:tag= "TelId3"/> <com.example.circle.trapezoi Dimagebutton android:id= "@+id/telid4" android:layout_centerinparent= "true" android:layout_width= "wrap _content "Android: layout_height= "wrap_content" android:background= "@drawable/select_menu_4" android:tag= "TelId4"/> <com.example.circle.trapezoidimagebutton android:id= "@+id/telid5" Android:layout_centerinpa Rent= "true" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:backgrou nd= "@drawable/select_menu_5" android:tag= "TelId5"/></relativelayout>
where the custom ImageButton
public class Trapezoidimagebutton extends ImageButton {public Trapezoidimagebutton (context context, AttributeSet attrs , int defstyle) {Super (context, attrs, Defstyle); } public Trapezoidimagebutton (context context, AttributeSet Attrs) {Super (context, attrs); } public Trapezoidimagebutton (context context) {super (context); } @Override public boolean ontouchevent (Motionevent event) {if (Istouchpointinview (Event.getx (), Event.gety () )|| Event.getaction ()! = Motionevent.action_down) {return super.ontouchevent (event); }else{return false; }} protected Boolean Istouchpointinview (float localx, float localy) {Bitmap Bitmap = Bitmap.createbitmap (Getwidt H (), GetHeight (), config.argb_8888); Canvas canvas = new canvas (bitmap); Draw (canvas); int x = (int) localx; int y = (int) localy; if (x < 0 | | x >= getwidth ()) return false; if (Y < 0 | | y >= getheight ()) return false; IntPixel = Bitmap.getpixel (x, y); if ((pixel&0xff000000)! = 0) {//is not transparent, here is the key. return true; }else{return false; } }}
Main activity:
Package Com.example.circle;import Android.app.activity;import Android.app.actionbar;import android.app.Fragment; Import Android.os.bundle;import android.view.layoutinflater;import android.view.menu;import Android.view.MenuItem; Import Android.view.view;import Android.view.view.onclicklistener;import Android.view.viewgroup;import Android.widget.toast;import Android.os.build;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); if (savedinstancestate = = null) {Getfragmentmanager (). BeginTransaction (). Add (R.id.container, new placeholderfragment ()). commit ();}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar will//AutomatIcally handle clicks on the Home/up button, so long//as you specify a parent activity in AndroidManifest.xml.int ID = ite M.getitemid (); if (id = = r.id.action_settings) {return true;} return super.onoptionsitemselected (item);} /** * A placeholder fragment containing a simple view. */public Static class Placeholderfragment extends Fragment {private Activity mactivity;public placeholderfragment () {}@ Overridepublic View Oncreateview (Layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {view Rootview = Inflater.inflate (R.layout.fragment_main, container,false); mactivity = Getactivity (); Rootview.findviewbyid (R.ID.TELID1). Setonclicklistener (onclick); Rootview.findviewbyid (R.ID.TELID2). Setonclicklistener (onclick); Rootview.findviewbyid (R.ID.TELID3). Setonclicklistener (onclick); Rootview.findviewbyid (R.ID.TELID4). Setonclicklistener (onclick); Rootview.findviewbyid (R.ID.TELID5). Setonclicklistener (onclick); return rootview;} Public Onclicklistener onclick = new Onclicklistener () {@Overridepublic void OnClick (View v) {toast.maketext (mactivity, V.gettag (). toString (), 1*1000). Show ();}; }}
Here also share a demo source code click on the Open link
Android Turntable button effect cleverly implemented