2012-10-10 53 views
3

我想讓我的應用程序更加用戶友好,所以我正在考慮顯示一種覆蓋,當用戶第一次啓動應用程序時突出顯示不同的組件。顯示某種幫助'覆蓋'

什麼是開始實施這個最好的方法?

下面是一個例子:

enter image description here

回答

4

overlay

我知道這是很舊,但我發現這一點,並做了一些細微的修改。對我很好。

創建和複製你的 「overlay.png」 文件到 「繪製」

創建佈局/ overlay_activity.xml

<?xml version="1.0" encoding="utf-8"?> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/Overlay_activity" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background= "@null" 
     android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/ivOverlayEntertask" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/overlay" /> 

</LinearLayout> 

創建XML/overlay_prefs.xml

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > 

    <CheckBoxPreference 
     android:defaultValue="true" 
     android:key="overlaypref" 
     android:summary="Enable Overlay Screen" 
     android:title="Overlay Screen" /> 

</PreferenceScreen> 

在你SharedPreferences的活動,創建和實例以及用於存儲值的布爾值:

SharedPreferences setOverlay; 
boolean showOverlay; 

然後在OnCreate中獲得的價值爲覆蓋CheckBoxPreference,如果這是真的,覆蓋在圖像上的活動:

setOverlay = PreferenceManager.getDefaultSharedPreferences(this); 
showOverlay = setOverlay.getBoolean("overlaypref", true); 
    if (showOverlay == true) { 
    showActivityOverlay(); 
    } 

在活動創建一個新方法:showActivityOverlay() 什麼這個方法確實是,它顯示活動開始時的覆蓋圖,然後當用戶點擊屏幕時,它會將「overlaypref」設置爲「false」,並不再顯示覆蓋圖。

private void showActivityOverlay() { 
     final Dialog dialog = new Dialog(this, 
     android.R.style.Theme_Translucent_NoTitleBar); 

     dialog.setContentView(R.layout.overlay_activity); 

     LinearLayout layout = (LinearLayout) dialog 
     .findViewById(R.id.overlay_activity); 
     layout.setBackgroundColor(Color.TRANSPARENT); 
     layout.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       dialog.dismiss(); 
       SharedPreferences.Editor editor = setOverlay.edit(); 
       editor.putBoolean("overlaypref", false); 
       editor.commit(); 
      } 
     }); 
     dialog.show(); 
    } 
1

使用幀或相對佈局。

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> 
    <include layout="@layout/normalLayout" /> 
    <include layout="@layout/overlayLayout" /> 
</RelativeLayout> 

在你的onCreate,檢查是否需要覆蓋,如果你這樣做,給的setContentView覆蓋版本。當他們點擊時,您可以將覆蓋圖或setContentView隱藏到常規佈局。