蒙版提示頁(添加新功能後的一種提示)

其實提示頁自己就是一個佈局,裏面有一張或是幾張圖片,向用戶提示在當前版本有新添加了某個功能,引導用戶使用,通常只會出現一次。android

先上佈局代碼:ide

 1     
 2 <?xml version="1.0" encoding="utf-8"?>
 3 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:id="@+id/parentlayout"
 5     android:layout_width="fill_parent"
 6     android:layout_height="fill_parent"
 7     android:background="@color/all_backgroud" >
 8 
 9 
10       .
11       .(這裏省略無關的代碼)
12       .
13 
14 <LinearLayout
15         android:id="@+id/linearLayout_mask"
16         android:layout_width="fill_parent"
17         android:layout_height="fill_parent"(注意設置全屏)
18         android:background="@drawable/share_mask_back"
19         android:gravity="top"(適當的方位也很重要)
20         android:visibility="gone" >
21 
22         <ImageView
23             android:id="@+id/imageView_mask"
24             android:layout_width="fill_parent"
25             android:layout_height="wrap_content"
26             android:background="@drawable/share_mask"(美工設計的引導提示圖片)
27             android:scaleType="fitStart" >
28         </ImageView>
29     </LinearLayout>
30     
31 </RelativeLayout>
share_mask_back背景設置代碼(半透明):
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 3 >
 4     <gradient 
 5         android:startColor="#d2000000"
 6         android:centerColor="#d2000000"
 7         android:endColor="#d2000000" 
 8         android:shape="rectangle"
 9         android:centerX="-5"
10         android:angle="0"
11     />
12 </shape>

 

主要代碼:佈局

 1  1
 2 /** 初次進入時候的蒙版背景 */
 3 private LinearLayout linearLayout_mask;  
 4 /** 初次進入時的蒙版圖片 */
 5 private ImageView imageView_mask;
 6 
 7 //蒙版相關初始化
 8 linearLayout_mask = (LinearLayout)findViewById(R.id.linearLayout_mask);
 9 imageView_mask = (ImageView)findViewById(R.id.imageView_mask);
10 
11 //設置監聽
12 
13 linearLayout_mask.setOnClickListener(this);
14 
15  @Override
16 
17       public void onClick(View v) {
18           // TODO Auto-generated method stub
19           switch (v.getId()) {
20           case R.id.linearLayout_mask://分享蒙版監聽,截取蒙板下方的點擊事件
21               break;
22              
23           case R.id.imageView_mask://分享蒙版上的按鈕
24               linearLayout_mask.setVisibility(View.GONE);
25              context.getSharedPreferences("Setting", Context.MODE_PRIVATE).edit().putBoolean("read_share", true).commit();
26             break;
27             
28         default:
29              break;
30          }
31     }
32 
33   setMask();//設置蒙版,通常在oncreat()裏面設置
34 
35 /**
36      * 設置第一次進入時的蒙版
37      */
38     private void setMask() {
39         
40         SharedPreferences sharedPreferences = context.getSharedPreferences(
41                 "Setting", Context.MODE_PRIVATE);
42         boolean isread =  sharedPreferences.getBoolean("read_share", false);
43         if(!isread){
44             // 調整頂部背景圖片的大小,適應不一樣分辨率的屏幕
45             DisplayMetrics dm = new DisplayMetrics();
46             getWindowManager().getDefaultDisplay().getMetrics(dm);
47             int width = dm.widthPixels;
48             int height = (int) ((float) width / 48 *31);
49             imageView_mask.setLayoutParams(new LinearLayout.LayoutParams(width, height));
50             linearLayout_mask.setVisibility(View.VISIBLE);
51         }else{
52             linearLayout_mask.setVisibility(View.GONE);
53         }
54     }

效果以下:this

             

相關文章
相關標籤/搜索