国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 新手引導蒙層效果實現代碼示例

2019-12-12 04:06:02
字體:
來源:轉載
供稿:網友

先上效果圖:

這個效果一開始我是想直接讓UI給個切圖,后來發現這樣不行,適配很差,達不到效果。所以就自己動手寫代碼,其實思路也很簡單:在這個布局的父布局上面再手動添加一個view(通常LinearLayout比較方便),然后把這個linearlayout的背景設置成#88000000,之后就是給這個linearlayout動態增加子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是手機狀態欄的高度    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);  }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吴旗县| 武乡县| 阿瓦提县| 灵山县| 龙陵县| 景泰县| 乐亭县| 衡东县| 股票| 万安县| 三原县| 东乌珠穆沁旗| 丰城市| 洪洞县| 延吉市| 新巴尔虎左旗| 开原市| 大田县| 安远县| 道真| 岳西县| 延川县| 栾城县| 郴州市| 临泽县| 怀宁县| 淮滨县| 白银市| 清原| 邯郸县| 改则县| 石屏县| 台东市| 湾仔区| 乌鲁木齐县| 四川省| 昭通市| 手游| 定州市| 甘孜| 南华县|