【发布时间】:2017-08-17 21:25:07
【问题描述】:
这将是一个棘手的问题,但不是针对你们,而是针对我。
解释我想要什么会很困难,所以请耐心等待。
我正在使用 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>
这个布局文件中最重要的是 FrameLayout id container 和 SwitchButton id 为 turnOn 。
容器和SwitchButton中有一个ClickListener。第一个触发另一个 Fragment,第二个触发 Switch。
问题是,如果 SwitchButton 因单击或滑动而被禁用,则单击操作会转到 容器,这不是我想要的。我尝试了代码中的所有内容,但我认为我的问题出在布局文件中......
例如:如果 SwitchButton 被阻止单击或滑动,则用户不应对该按钮执行任何操作,而是发生的情况是当用户单击被阻止的按钮时点击进入容器,执行不需要的操作。
注意:即使 SwitchButton 被阻止,用户自己也可以选择点击 容器,但我不希望 >容器在被阻止的按钮中单击时被触发。
如果你们要求更多关于我将在此处提供的代码的信息,我已尽力解释我的问题。
一如既往的感谢, 伊戈尔·莫尔斯。
【问题讨论】:
-
If the SwitchButton is blocked to click or swipe你是如何实现这部分的? -
我刚刚使用 SwitchButton.setEnabled(false) 禁用了它,并确保我将 setClikable 设置为 true。
-
如果视图处于禁用状态(即
spinner.setEnabled(false)或android:enabled="false"),则不允许触摸事件向上移动。如果您仍然遇到该问题,请在 github 上发布一个具有该行为的简单项目。
标签: android android-layout listview android-fragments