Android通过应用程序绘制不可点击的布局
问题描述:
我有一个布局,我将其他应用程序设置为match_parent来填充整个屏幕。在这个布局中,我有一个聊天头,可以拖动并单击以显示更多信息。通常情况下,我会将布局设置为wrap_content,并只占用我需要的屏幕空间,但Android SpringAnimations在没有大型父母的情况下无法使用我的聊天头。Android通过应用程序绘制不可点击的布局
我遇到的问题是我无法与我在上面绘制布局的背景进行交互。我以前尝试使用XML和编程方式设置RelativeLayout root_container
至clickable: false
和focusable: 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);
感谢您抽空看看!
答
通过一些研究,我发现这是不可能的,因为它可能允许各种恶意机会。如果视图制作为FLAG_NOT_TOUCHABLE
,则不能与其进行交互,并且如果尝试分派触摸事件,则它们将不会进入主屏幕。解决方案仅仅是重构,所以父视图不会填充主屏幕。
试着用'clickable:false'设置'@ + id/root_container' ....并用'clickable:true'设置'@ + id/collapse_view' ...回报会发生什么 – MohammedAlSafwan
@MohammedAlSafwan没有运气! “可点击:false”似乎没有注册。我应该注意聊天头里有一个onTouch监听器,所以它也可以点击。 –