本篇內(nèi)容介紹了“Android怎么實現(xiàn)自定義View展開菜單功能”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
效果圖
思路
1.下角Button的父View加入一個FrameLayout,也就是圖中全屏透明灰色部分。
菜單沒有彈出的時候設(shè)置為不可見。
設(shè)置FrameLayout點擊事件,點擊的時候縮回菜單。
對應init()
2.rameLayout中加入菜單按鈕,也就是彈出的那三個。
菜單沒有彈出的時候設(shè)置為不可見。
對應addElement()和freshElement()
3.右下角的按鈕,旋轉(zhuǎn)圖標(也可以不旋轉(zhuǎn))。
對應setRotateAnimation()
4.性動畫將fragment的透明度從0調(diào)到1
對應changeBackgroudStatus()
5.單按鈕設(shè)為可見,并向周圍彈出
對應setTranslation()
點我查看源代碼
使用方法:
在XML文件中,這個父類是FloatingActionButton:
<com.ice.view.UnfoldButton android:id="@+id/unfoldButton" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginRight="20dp" android:layout_marginBottom="18dp" app:elevation="5dp" app:borderWidth="0dp" android:layout_gravity="right" android:src="@drawable/add" android:background="@color/colorAccent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" />
在Activity中:
UnfoldButton f = (UnfoldButton) findViewById(R.id.unfoldButton); f.addElement(R.drawable.bestjay, new View.OnClickListener() { @Override public void onClick(View v) { //這里寫菜單的點擊事件 } }); f.addElement(R.drawable.bestjay,null);//同上 f.addElement(R.drawable.bestjay,null);//同上 f.setmRotatable(true);//設(shè)置圖標是否旋轉(zhuǎn) 默認為true f.setmScale(1);//設(shè)置彈出縮放的比例 1為不縮放 范圍是0—1 f.setLength(250);//設(shè)置彈出的距離
彈出菜單后,背景顏色由你自己定,你需要在colors.xml里面聲明一個color:
<color name="background">#9b414141</color>
name必須是”background”
“Android怎么實現(xiàn)自定義View展開菜單功能”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
本文題目:Android怎么實現(xiàn)自定義View展開菜單功能-創(chuàng)新互聯(lián)
路徑分享:http://www.rwnh.cn/article28/gegcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、用戶體驗、手機網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)