我遇到了一个问题,即 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/