Android 新手引導蒙層效果實現(xiàn)代碼示例
更新時間:2017年01月06日 16:28:37 作者:Kevin_Xu1114
本篇文章主要介紹了Android 新手引導蒙層效果實現(xiàn)代碼示例,具有一定的參考價值,有興趣的可以了解一下。
先上效果圖:

這個效果一開始我是想直接讓UI給個切圖,后來發(fā)現(xiàn)這樣不行,適配很差,達不到效果。所以就自己動手寫代碼,其實思路也很簡單:在這個布局的父布局上面再手動添加一個view(通常LinearLayout比較方便),然后把這個linearlayout的背景設置成#88000000,之后就是給這個linearlayout動態(tài)增加子view,初步效果就能達到。
下面直接上代碼:
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);//背景設置灰色透明
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坐標 nearby這個控件對應就是需要高亮顯示的地方
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是手機狀態(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);
}
}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Android nativePollOnce函數(shù)解析
這篇文章主要介紹了Android nativePollOnce函數(shù)解析的相關資料,幫助大家更好的理解和學習使用Android,感興趣的朋友可以了解下2021-03-03
Android Studio出現(xiàn)Failed to pull selection: open failed: Permi
本篇文章給大家分享了Android Studio中導出數(shù)據(jù)庫文件的方法以及出現(xiàn)Failed to pull selection: open failed: Permission denied的解決思路,有興趣的學習下。2018-05-05
Android編程實現(xiàn)ListView內容無限循環(huán)顯示的方法
這篇文章主要介紹了Android編程實現(xiàn)ListView內容無限循環(huán)顯示的方法,通過繼承Adapter類實現(xiàn)ListView中的數(shù)據(jù)無限循環(huán)顯示功能,需要的朋友可以參考下
2017-06-06 
