- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这将是一个棘手的问题,但不是对你们而是对我而言。
解释我想要什么会很困难,所以请耐心等待。
我正在使用 AdvancedRecyclerView 库,特别是 Draggable 和 Swipping 库
这是我为列表中的每个项目使用的布局:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Haruki Hasegawa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- NOTE: should use FrameLayout or RelativeLayout for parent of the "@id/container" view (for Android 2.3 compatibility) -->
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/commonListItemStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_margin="4dp"
android:background="@drawable/bg_swipe_item_neutral">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
tools:ignore="UselessParent">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_gravity="top|left"
android:background="#20000000"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/list_divider_v"
android:orientation="horizontal">
<View
android:id="@+id/drag_handle"
android:layout_width="15dp"
android:layout_height="match_parent"
android:layout_gravity="top|left"
android:background="@color/material_grey300"
android:visibility="visible" />
<LinearLayout
android:layout_width="244dp"
android:layout_height="match_parent"
android:divider="@drawable/list_divider_v"
android:dividerPadding="4dp"
android:orientation="vertical"
android:showDividers="middle"
android:weightSum="3">
<TextView
android:id="@+id/deviceName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_vertical|center_horizontal"
android:text="deviceName" />
<TextView
android:id="@+id/deviceDescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="deviceDescription" />
</LinearLayout>
<com.kyleduo.switchbutton.SwitchButton
android:id="@+id/turnOn"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:kswBackMeasureRatio="2.2"
app:kswBackRadius="2dp"
app:kswTextOff="Off"
app:kswTextOn="On"
app:kswThumbRadius="2dp" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</FrameLayout>
这个Layout文件中最重要的是id为container的FrameLayout和id为turnOn的SwitchButton .
在container 和SwitchButton 中有一个ClickListener。第一个触发另一个 Fragment,第二个触发 Switch。
问题是,如果 SwitchButton 因单击或滑动而被禁用,则单击操作会转到 容器,这不是我想要的。我尝试了代码中的所有内容,但我认为我的问题出在布局文件中...
例如:如果 SwitchButton 被阻止点击或滑动,用户不应该用那个按钮做任何事情,而是当用户点击被阻止的按钮时发生的事情单击转到容器,将执行不需要的内容。
注意:即使SwitchButton被屏蔽,用户自己也可以选择点击容器,但我不希望>容器在被阻止的按钮中被点击时被触发。
我已尽力解释我的问题,如果你们需要有关我将在此处提供的代码的更多信息。
一如既往的感谢,伊戈尔·莫尔斯。
最佳答案
您的问题来自 SwitchButton
库的实现。
当您将 View.OnClickListener
附加到您的 SwitchButton
并且启用了开关时,一切都会按预期进行,因为点击会转到该点击监听器。但是,当开关被禁用时,点击会转到 SwitchButton
的 onTouchEvent()
实现。这是该方法的第一部分(来自 SwitchButton
source 代码):
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled() || !isClickable() || !isFocusable()) {
return false;
}
如果您查看onTouchEvent()
的文档,您会发现:
Returns: True if the event was handled, false otherwise.
因此 SwitchButton 库明确表示它不处理点击,并且这些点击应该在 View 层次结构中向上冒泡。
我看到两个相对简单的解决方案。
首先是创建您自己的 SwitchButton
自定义子类,并更改 onTouchEvent()
以在禁用时消耗点击:
public class MySwitchButton extends SwitchButton {
public MySwitchButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return !isEnabled() || super.onTouchEvent(event);
}
}
第二种是将您的 SwitchButton
包装在另一个 View 中,并为该包装器分配一个 View.OnClickListener
以拦截点击事件:
<FrameLayout
android:id="@+id/interceptor"
...>
<com.kyleduo.switchbutton.SwitchButton
.../>
</FrameLayout>
在 Java 中:
findViewById(R.id.interceptor).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do nothing
}
});
就我个人而言,我更喜欢第一种。
关于Android AdvancedRecyclerView SwitchButton 阻止点击进入父布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45745168/
如果我 mov, eax 12345 和之后的 mov var, eax (假设 var 是一个 32 位的 int 等..等等)并输出 var 稍后它会正确输出。 与 ax 相同。 mov ax,
我有这个代码: for($nrt=0; $nrt"; if($sidesIndexes[$nrt]==$nrt) { echo "am I in??? ".$sidesInde
我正在阅读The Go Programming Language的8.5章,并陷入一些代码。下面的代码列表。 func main() { naturals := make(chan int)
我写了一个 MySQL 查询用于将数据导出到文本文件。 查询运行成功,但结果与我的预期不符。 我想在列之间没有间距的结果。 select sample_export_record1_2013.
在普通的 Excel 窗口中,我可以打开 VBE 并通过触摸键序列插入一个新模块:ALT+F11、ALTim 全部不使用鼠标。有没有办法打开 VBE 并导航到 本工作手册 不使用鼠标的代码区域? 最佳
我正在使用 axios 发出 http 请求。在 .then() 内部,我正在使用另一个 axios 调用。最后,我有第三个 then(),它应该在第二个 then 之后运行,但实际上并没有这样做。
我需要在 cocos2d 项目中播放视频..我的问题是:如何将 MPMoviePlayerController 放入我的 View 中,如下所示:? UIView *theView = [[CCDir
我正在学习 Angular。以下代码有效: .controller('abc', function ($scope, $http) { $http.get("/Handlers/Authenticat
目前我正在使用 WPF 学习 C#。我的主要方法是尽我所能使用 MVVM 模式,但现在我有点困惑。 在我所有 View 的应用程序中,我有一个 View 模型: private DruckviewVi
关于将 G 邮件提取到 Google 电子表格,我该如何添加 IF 以按主题驳回特定电子邮件?例如:电子邮件回复(主题中带有“RE:”)。我不希望这些电子邮件出现在我的电子表格中。 我尝试过使用 LO
我正在尝试使用 Spotify API 并进入数组。 const App = () => { const [isLoading, setIsLoading] = useState(true);
我有一个 html 模板,并且有一个条件为 --> 的代码 --> window.jQuery || document.write(""+"");
我正在开发一个 Android 应用程序,该应用程序会暴力破解从 int 创建的 MD5 和。 暴力破解部分工作正常。 (我可以sysout最终值并且它是正确的。) 我在将输出值发送到警报对话框时遇到
我正在创建一个界面,用户可以通过该界面生成多系列折线图,并控制绘制哪些数据集。 要绘制哪些数据集由复选框控制。页面加载时,默认数据集以图表形式呈现,并且 $('input:checkbox.data-
我尝试将有向无环图绘制为力布局。 但是我注意到,尽管为每个组元素灌输了进入/退出条件,弹出的节点/链接并没有从 DOM 中删除它们自己。 相反,弹出的节点/链接在力布局中卡住;这意味着没有调用进入/退
这里是新手。我不知道它是怎么发生的,但我正在处理一个程序,当我去调试并进入时,黄色箭头走到了我代码的最后并跳过了整个 block 。有快速解决方法吗? 最佳答案 按 F11,或单击工具栏上的“Step
我的 Action 栏 sherlock 中有一个列表。我想在用户点击该列表时得到。我不想知道用户何时点击某个项目,我已经知道 (onNavigationItemSelected)。 在我的 onCr
** 你好 **我如何从 ci 中的 mysql 日期获取 eurodate 来工作......无法弄清楚 - 请帮忙 想要获取日期 YY-mm- dd -> dd-mm-yy提前致谢 最佳答案 $t
我有以下脚本: #!/bin/bash ls -1 | while read d do [[ -f "$d" ]] && continue echo $d cd $d done
TL;DR - 跳转到最后一段 背景 我正在执行一些数据驱动测试,并将日志文件用作测试输出之一。它的工作原理是这样的- 读取文件夹中的第一个文件 处理第一行并转换为测试 运行测试 执行验证 1 ...
我是一名优秀的程序员,十分优秀!