2014-10-06 86 views
0

我發現這個最優秀的解決方案,我想在這裏解決的具體問題:的Android的FrameLayout前景setAlpha不工作

Blur or dim background when Android PopupWindow active

但是,我不能讓父視圖通過設置阿爾法暗淡。我正在使用矩形形狀,因爲解決方案建議Drawable是一個GradientDrawable。以下是我正在使用的代碼:

   @Override 
       public void onViewPhoto(PostObject item) { 
        rootView.getForeground().setAlpha(220); 
        rootView.invalidate(); 
        PhotoPopup pp = new PhotoPopup(getActivity(), rootView, item.getObject_Id()); 
        pp.show(); 
        rootView.getForeground().setAlpha(0); 
        rootView.invalidate(); 
       } 

上面的代碼位於將承載彈出窗口的父代片段中。它通過自定義回調調用。當用戶點擊列表視圖項中的照片時,該調用由ArrayAdapter派生適配器完成。

我試過這兩個KitKat(華碩備忘錄墊)和果凍豆(三星Galaxy Tab 2) 任何想法?

出於完整性:這裏的佈局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/streamList_rootFrame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:foreground="@drawable/shape_dim_window" > 

    <ListView 
     android:id="@+id/streamList_listview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </ListView> 

</FrameLayout> 

而且本身的形狀:

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <solid android:color="#000000" /> 
</shape> 

回答

0

您可以通過使用android:theme="@android:style/Theme.Dialog"做使用DIALOG。 創建活動,並在您AndroidManifest.xml活動定義爲:

<activity android:name=".activity.YourActivity" 
android:label="@string/your_activity_label" 
android:theme="@android:style/Theme.Dialog"> 

這將創建一個popup和你的背景將是暗淡的。

+0

非常感謝您的快速響應。這可能是我必須考慮的事情,但是,我已經在我正在使用的解決方案中投入了大量代碼,並且我很想知道爲什麼我所做的不工作。如果可能的話,我希望能夠進行簡單的修復。 – psparago 2014-10-06 13:31:08

+0

我同意這個答案......在'FrameLayout'中包裝'ListView'不僅更加複雜,而且最終效率會更低(GPU需要畫兩倍的像素......一次前景框架佈局和列表視圖)。如果您使用半透明的活動對話框,GPU將能夠優化這種背景淡化效果。 – 2014-10-06 15:46:03

+0

我猜想一些背景已丟失。我已經走下了對話路線,並且爲了我想要做的事情,它不能很好地工作。我選擇了彈出式窗口,因爲它在移動,移動等方面似乎更好地移動,投擲等。這是一個特殊需求導向的應用程序,所以平滑運動是必不可少的我無法從對話中獲得相同的動作和手勢表現。 – psparago 2014-10-06 19:20:48