這篇文章主要為大家展示了如何實(shí)現(xiàn)Android自定義轉(zhuǎn)盤菜單,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來(lái)看看吧。
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)上猶免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。最近由于公司項(xiàng)目需要,需要開(kāi)發(fā)一款轉(zhuǎn)盤菜單,費(fèi)了好大功夫搞出來(lái)了,下面分享下
樣圖
具體功能如下:
import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; import com.hitomi.smlibrary.OnSpinMenuStateChangeListener; import com.hitomi.smlibrary.TurnTableMenu; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private TurnTableMenu turnTableMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); turnTableMenu = (TurnTableMenu) findViewById(R.id.spin_menu); // 設(shè)置頁(yè)面標(biāo)題 ListhintStrList = new ArrayList<>(); hintStrList.add("熱門信息"); hintStrList.add("實(shí)時(shí)新聞"); hintStrList.add("我的論壇"); hintStrList.add("我的信息"); hintStrList.add("環(huán)游世界"); hintStrList.add("閱讀空間"); hintStrList.add("歡樂(lè)空間"); hintStrList.add("系統(tǒng)設(shè)置"); turnTableMenu.setHintTextStrList(hintStrList); turnTableMenu.setHintTextColor(Color.parseColor("#FFFFFF")); turnTableMenu.setHintTextSize(14); // 設(shè)置頁(yè)面適配器 final List fragmentList = new ArrayList<>(); fragmentList.add(Fragment1.newInstance()); fragmentList.add(Fragment2.newInstance()); fragmentList.add(Fragment3.newInstance()); fragmentList.add(Fragment4.newInstance()); fragmentList.add(Fragment5.newInstance()); fragmentList.add(Fragment6.newInstance()); fragmentList.add(Fragment7.newInstance()); fragmentList.add(Fragment8.newInstance()); FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { return fragmentList.get(position); } @Override public int getCount() { return fragmentList.size(); } }; turnTableMenu.setFragmentAdapter(fragmentPagerAdapter); // 設(shè)置菜單狀態(tài)改變時(shí)的監(jiān)聽(tīng)器 turnTableMenu.setOnSpinMenuStateChangeListener(new OnSpinMenuStateChangeListener() { @Override public void onMenuOpened() { Toast.makeText(MainActivity.this, "SpinMenu opened", Toast.LENGTH_SHORT).show(); } @Override public void onMenuClosed() { Toast.makeText(MainActivity.this, "SpinMenu closed", Toast.LENGTH_SHORT).show(); } }); } }