2013-12-20 64 views
0

我有RelativeLayout,我想在窗口中显示。 我做这样的方式:WindowManager只显示背景

static WindowManager wManager;  

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN, android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN, android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT); 
       wManager = (WindowManager) activity_home.getSystemService(Context.WINDOW_SERVICE); 
       LayoutInflater inflater = (LayoutInflater) activity_home.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.order_wait, null); 
    wManager.addView(view, params); 

但我只看到RelativeLayout的背景,并没有看到它的内容。

order_wait.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 

    <LinearLayout 
     android:id="@+id/ll_oder" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/gray_without_corners" 
     android:orientation="vertical" 
     android:layout_marginTop="80dp" 
     > 

     <FrameLayout 
      android:id="@+id/fr_poisk" 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="5dp" > 

      <TextView 
       android:id="@+id/txt_poisk" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="Автомобиль будет через:" 
       android:textColor="#000000" 
       android:textSize="20sp" 
       android:textStyle="bold" /> 
     </FrameLayout> 

     <TextView 
      android:id="@+id/txt_timer" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="0:30" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#111111" 
      android:textSize="60sp" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/ll_bot" 
     android:layout_width="match_parent" 
     android:layout_height="65dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="#B6B6B6" > 

     <Button 
      android:id="@+id/bt_cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_marginTop="4dp" 
      android:layout_weight="1" 
      android:background="@drawable/but_yellow" 
      android:text="ОТМЕНА" 
      android:textColor="#1e90ff" 
      android:textSize="20dp" /> 
    </LinearLayout> 

</RelativeLayout> 

感谢您的答案。

回答

0

对于inflater.inflate(R.layout.order_wait, null)你可以尝试给wManager作为根,而不是null?

+0

我该怎么做? WindowManager没有获取ViewGroup的方法。 – Artem

+0

嗨,我已经添加android.permission.SYSTEM_ALERT_WINDOW清单,我可以看到你的原代码正在运行。请尝试添加此权限并查看。 – Sheshu

+0

我有此权限。不起作用。 Thahk你 – Artem