Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例
先上效果圖:

這個效果一開始我是想直接讓UI給個切圖,后來發(fā)現(xiàn)這樣不行,適配很差,達(dá)不到效果。所以就自己動手寫代碼,其實(shí)思路也很簡單:在這個布局的父布局上面再手動添加一個view(通常LinearLayout比較方便),然后把這個linearlayout的背景設(shè)置成#88000000,之后就是給這個linearlayout動態(tài)增加子view,初步效果就能達(dá)到。
下面直接上代碼:
public void showGuideView() {
View view = getWindow().getDecorView().findViewById(R.id.activity_main);
if (view == null) return;
ViewParent viewParent = view.getParent();
if (viewParent instanceof FrameLayout) {
final FrameLayout frameParent = (FrameLayout) viewParent;//整個父布局
final LinearLayout linearLayout = new LinearLayout(this);//新建一個LinearLayout
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setBackgroundResource(#88000000);//背景設(shè)置灰色透明
linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
frameParent.removeView(linearLayout);
}
});
Rect rect = new Rect();
Point point = new Point();
nearby.getGlobalVisibleRect(rect, point);
//獲得nearby這個控件的寬高以及XY坐標(biāo) nearby這個控件對應(yīng)就是需要高亮顯示的地方
ImageView topGuideview = new ImageView(this);
topGuideview.setLayoutParams(new ViewGroup.LayoutParams(rect.width(), rect.height()));
topGuideview.setBackgroundResource(R.drawable.iv_topguide);
Rect rt = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rt);
topGuideview.setY(point.y - rt.top);//rt.top是手機(jī)狀態(tài)欄的高度
ImageView bottomGuideview = new ImageView(this);
bottomGuideview.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
bottomGuideview.setBackgroundResource(R.drawable.iv_bottomguide);
bottomGuideview.setY(point.y + topGuideview.getHeight());
linearLayout.addView(topGuideview);
linearLayout.addView(bottomGuideview);
frameParent.addView(linearLayout);
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android ProgressDialog用法之實(shí)現(xiàn)app上傳文件進(jìn)度條轉(zhuǎn)圈效果
- Android Volley擴(kuò)展實(shí)現(xiàn)支持進(jìn)度條的文件上傳功能
- Android實(shí)現(xiàn)文件上傳和下載倒計時功能的圓形進(jìn)度條
- Android上傳文件到服務(wù)端并顯示進(jìn)度條
- Android帶進(jìn)度條的文件上傳示例(使用AsyncTask異步任務(wù))
- Android頁面中引導(dǎo)蒙層的使用方法詳解
- Android實(shí)現(xiàn)新手引導(dǎo)半透明蒙層效果
- Android實(shí)現(xiàn)圖片上傳蒙層進(jìn)度條
相關(guān)文章
Android開發(fā)Jetpack組件Room使用講解
Room是一個數(shù)據(jù)庫訪問組件; 對SqLite數(shù)據(jù)庫做了友好的封裝,使我們在編碼的時候,只需要注重邏輯的部分即可,數(shù)據(jù)庫就交給Room去流暢的訪問即可2022-08-08
android手機(jī)端與PC端使用adb forword通信
這篇文章主要介紹了android手機(jī)端與PC端使用adb forword通信的相關(guān)資料,需要的朋友可以參考下2017-04-04
淺談Android Activity與Service的交互方式
下面小編就為大家?guī)硪黄獪\談Android Activity與Service的交互方式。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-09-09
Android Studio時間選擇器的創(chuàng)建方法
這篇文章主要為大家詳細(xì)介紹了Android Studio時間選擇器的創(chuàng)建方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
android模擬器開發(fā)和測試nfc應(yīng)用實(shí)例詳解
本文介紹android模擬器開發(fā)nfc應(yīng)用詳解,大家參考使用吧2013-12-12
Android開發(fā)之圖形圖像與動畫(四)AnimationListener簡介
就像Button控件有監(jiān)聽器一樣,動畫效果也有監(jiān)聽器,只需要實(shí)現(xiàn)AnimationListener就可以實(shí)現(xiàn)對動畫效果的監(jiān)聽,感興趣的朋友可以了解下啊,希望本文對你有所幫助2013-01-01
Android 基于Socket的聊天應(yīng)用實(shí)例(二)
本篇文章主要介紹了Android 基于Socket的聊天應(yīng)用實(shí)例,具有一定的參考價值,有需要的可以了解一下。2016-12-12
Android 自定義Button控件實(shí)現(xiàn)按鈕點(diǎn)擊變色
這篇文章給大家介紹了android 自定義Button控件實(shí)現(xiàn)按鈕點(diǎn)擊變色的代碼,本文給大家附有注釋,非常不錯,代碼簡單易懂,對android按鈕點(diǎn)擊變色的實(shí)現(xiàn)感興趣的朋友參考下吧2016-11-11

