android - 如果显示所有组件并且 Android API 27 中还有空间,则 onClick 事件在 LinearLayout 中不起作用
问题描述
我正在使用可用于模拟设备的最大屏幕尺寸的 Android API 27 测试我的应用程序。
如果发生某种情况,如果用户在空白空间(没有 UI 元素的空间)或被动元素(如 TextView)中按下,我的应用程序应该能够做出反应。
从 API 18 到 26,如果在 LinearLayout 中的最后一个元素显示之后还有空间,如果用户按下它,它会做出相应的反应,但在 API 27 中它只是忽略它,但如果点击 TextView 之类的东西就可以工作。
我试图通过创建一个可以填充所有可用空间的不可见 TextView 来解决这个问题,要么将其放在最后一个元素上,要么将其放在中间,但它不起作用,我已经完成了这两种方式。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="false"
android:clickable="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity4"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="false"
android:clickable="true">
[moreelements]
<TextView
android:id="@+id/textViewextra"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="28dp"
android:gravity="center"
android:text=""
android:layout_weight="1"/>
</LinearLayout>
</ScrollView>
另一方面:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="false"
android:clickable="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity4"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="false"
android:clickable="true">
[moreelements]
<TextView
android:id="@+id/textViewextra"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="28dp"
android:gravity="center"
android:text=""
android:layout_weight="1"/>
[moreelements]
</LinearLayout>
</ScrollView>
但在 API 27 中,它甚至不会填满屏幕,并且仍然没有反应。
这个问题怎么解决?
解决方案
您本质上是希望空白空间可点击并执行一些操作?
<View
android:id="@+id/someId"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
将填充空白空间,然后为其设置一个 OnClickListener。
推荐阅读
- sql - 显示 Oracle DB 中表的上次访问时间
- python - 如何从 python 中的 cursor.execute() 中读取所有数据?
- oracle - MONTHS_BETWEEN / NTH_VALUE
- postgresql-9.5 - pgAgent 根据当前时间戳触发动作
- node.js - 将 MEAN 应用部署到 Heroku 空白页面
- excel - 自动插入日期
- c# - 如何在 C# 中使用 Windows 窗体打印对象
- javascript - angularjs中的owl.carosusel出错
- c++ - 如何通过 boost::iostream 防止 zip 炸弹
- r - 查找两个数据帧之间的重叠区域