gpt4 book ai didi

android - textIsSelectable 不适用于 descendantFocusability=blocksDescendants

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:32 24 4
gpt4 key购买 nike

我遇到了一个问题,即 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 接收焦点

更多信息请查看文档

Must be one of the following constant values in android:descendantFocusability.

  1. afterDescendants:- ViewGroup 只有在其后代都不需要时才会获得焦点。
  2. beforeDescendants:- ViewGroup 将在其任何后代之前获得焦点。
  3. 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com