2017-07-30 155 views
0

我有一個佈局,我將其他應用程序設置爲match_parent來填充整個屏幕。在這個佈局中,我有一個聊天頭,可以拖動並單擊以顯示更多信息。通常情況下,我會將佈局設置爲wrap_content,並只佔用我需要的屏幕空間,但Android SpringAnimations在沒有大型父母的情況下無法使用我的聊天頭。Android通過應用程序繪製不可點擊的佈局

我遇到的問題是我無法與我在上面繪製佈局的背景進行交互。我以前嘗試使用XML和編程方式設置RelativeLayout root_containerclickable: falsefocusable: false,但我仍然無法點擊其他任何內容。有沒有解決方案,我的root_container不會註冊點擊,但我的聊天頭可以繼續?

我覺得這個問題不同於其他不可聚焦/不可點擊的問題,因爲它涉及「繪製其他應用程序」功能,這可能會改變我不知道的東西。

<!--Root container - Causing the problems with elements beneath it--> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/root_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!--Small Chat head view that can be dragged around root_container--> 
    <RelativeLayout 
     android:id="@+id/collapse_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical" 
     android:visibility="visible"> 

     <ImageView 
      android:id="@+id/floating_icon" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:src="@drawable/floating_icon" 
      tools:ignore="ContentDescription" /> 

     <ImageView 
      android:id="@+id/close_button" 
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:layout_marginLeft="40dp" 
      android:src="@drawable/ic_close" 
      tools:ignore="ContentDescription" /> 
    </RelativeLayout> 
</RelativeLayout> 

編輯:我叫我的佈局,服務是這樣的:

mFloatingView = LayoutInflater.from(this).inflate(R.layout.layout_floating_view, null); 

final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
      WindowManager.LayoutParams.MATCH_PARENT, 
      WindowManager.LayoutParams.MATCH_PARENT, 
      WindowManager.LayoutParams.TYPE_PHONE, 
      WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
      PixelFormat.TRANSLUCENT); 

mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); 
mWindowManager.addView(mFloatingView, params); 

感謝您抽空看看!

+0

試着用'clickable:false'設置'@ + id/root_container' ....並用'clickable:true'設置'@ + id/collapse_view' ...回報會發生什麼 – MohammedAlSafwan

+0

@MohammedAlSafwan沒有運氣! 「可點擊:false」似乎沒有註冊。我應該注意聊天頭裏有一個onTouch監聽器,所以它也可以點擊。 –

回答

0

通過一些研究,我發現這是不可能的,因爲它可能允許各種惡意機會。如果視圖製作爲FLAG_NOT_TOUCHABLE,則不能與其進行交互,並且如果嘗試分派觸摸事件,則它們將不會進入主屏幕。解決方案僅僅是重構,所以父視圖不會填充主屏幕。