- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我遇到了一个问题,即 fragment 中的 ScrollView 自动滚动到底部。因此,为了解决此问题,我按照 this 中的建议在 RelativeLayout 中添加了以下行回答:
android:descendantFocusability="blocksDescendants"
但添加此行后,textIsSelectable
停止工作。如何添加这两行?
这是 XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:textSize="23sp"
android:text="The Beach Beneath the Street"
android:fontFamily="sans-serif-medium"
android:textColor="@color/black"
android:textIsSelectable="true"/>
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:padding="15dp"
android:fontFamily="sans-serif-condensed"
android:lineHeight="25dp"
android:lineSpacingMultiplier="1"
android:lineSpacingExtra="6dp"
android:textSize="16sp"
android:text="Never add a RecyclerView or ListView to a scroll view"
android:textIsSelectable="true" />
</RelativeLayout>
最佳答案
当您在 ViewGroup
中使用 android:descendantFocusability="blocksDescendants"
时,它将阻止其所有 subview 接收焦点
更多信息请查看文档
android:descendantFocusability
定义了在寻找一个View获取焦点时ViewGroup和它的后代之间的关系。
Must be one of the following constant values in
android:descendantFocusability
.
afterDescendants
:- ViewGroup 只有在其后代都不需要时才会获得焦点。beforeDescendants
:- ViewGroup 将在其任何后代之前获得焦点。blocksDescendants
:- ViewGroup 将阻止其后代获得焦点。现在你的问题
But after adding this line, textIsSelectable is stopped working for. How can I add both lines?
AFAIK你不能同时使用两者
您需要为 fragment 中自动滚动到底部的问题找到替代解决方案
这里有一些链接可能会帮助您解决 fragment 中自动滚动到底部的问题
关于android - textIsSelectable 不适用于 descendantFocusability=blocksDescendants,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54097016/
我正在尝试实现一个上下文菜单,但通过这样做我检查了我的 ListView 是否不可点击。 我根据这个主题浏览了不同的线程并尝试了所有建议的android:focusable="false"androi
我遇到了一个问题,即 fragment 中的 ScrollView 自动滚动到底部。因此,为了解决此问题,我按照 this 中的建议在 RelativeLayout 中添加了以下行回答: androi
我很难理解 descendantFocusability。非常特别afterDescendants。 有人可以给我举个例子说明什么时候有用吗? 最佳答案 在寻找 View 以获取焦点时,定义 View
由于 Recyclerview 中的 DescendantFocusability="blocksDescendants",我面临一些问题,我的编辑文本不可编辑。有一个 Activity 具有 Rec
我为 ListView 编写了自定义项目布局。该布局有许多小部件,有些将有自己的点击监听器。 当我单击该行时, ListView 的 onListItemClick 有时起作用,但有时不起作用。 在我
这已在 StackOverflow 上的许多帖子中得到解决。最推荐的解决方案是设置: android:descendantFocusability="blocksDescendants" 在列表项布局
我是一名优秀的程序员,十分优秀!