如何从 ScrollView 内的 RecyclerView 移除焦点? [英] How to remove focus from RecyclerView inside ScrollView?

查看:65
本文介绍了如何从 ScrollView 内的 RecyclerView 移除焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 ImageView 和 RecyclerView 的 Scrollview.如果导航抽屉打开然后关闭 RecyclerView 自动滚动到顶部,如何停止?

I have a Scrollview which contains an ImageView and RecyclerView. if navigation drawer opened then closed the RecyclerView auto scrolling to top, How to stop this?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollViewMain"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

       <ImageView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/imageView_main_icons_line"
           android:src="@drawable/main_line" />

              ...


       <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_activity_main_passenger_log"
            android:paddingBottom="2dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>
</ScrollView>
</RelativeLayout>

推荐答案

这个问题是因为recyclerView有默认焦点.

This problem because of recyclerView has default focus.

解决方案

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">

android:descendantFocusability="blocksDescendants" 添加到 scrollView 的直接布局中

Add android:descendantFocusability="blocksDescendants" to your immediate layout of scrollView

这篇关于如何从 ScrollView 内的 RecyclerView 移除焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆