相关疑难解决方法(0)

NestedScrollView中的Recycler视图导致滚动从中间开始

当我在NestedScrollView中添加RecyclerView时,我得到一个奇怪的滚动行为.

发生的事情是,只要滚动视图的行数多于屏幕中显示的行数,一旦启动活动,NestedScrollView就会从顶部开始偏移(图像1).如果滚动视图中的项目很少,以便可以一次显示它们,则不会发生这种情况(图2).

我使用的是支持库的23.2.0版.

图1:错误 - 从顶部偏移开始

图片1

图2:正确 - 回收者视图中的几个项目

图2

我粘贴在我的布局代码下面:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp">

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Title:"
                    style="@style/TextAppearance.AppCompat.Caption"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/bodyPadding"
                    style="@style/TextAppearance.AppCompat.Body1"
                    android:text="Neque porro quisquam est qui dolorem ipsum"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Subtitle:"
                    style="@style/TextAppearance.AppCompat.Caption"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/TextAppearance.AppCompat.Body1"
                    android:padding="@dimen/bodyPadding"
                    android:text="Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."/>

            </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv"
            android:focusable="false" …
Run Code Online (Sandbox Code Playgroud)

android android-support-library android-recyclerview android-nestedscrollview

112
推荐指数
6
解决办法
5万
查看次数

Android可在触摸模式下专注且可聚焦

我在表格布局中嵌套了编辑文本,然后在滚动视图中嵌入了表格布局,可触控模式中的可聚焦/可聚焦在真实设备中不起作用,但令人惊讶的是它在模拟器中有效.

请问一些提供替代解决方案吗?

android android-layout

8
推荐指数
1
解决办法
8202
查看次数

当nestedscrollview 中的recyclerview 滚动时,对讲焦点转到工具栏项

我的布局中有一个nestedscrollview,其中包含很少的文本、按钮和recyclerviews。

当对讲打开时,我可以遍历所有元素。但我面临一个问题。当我的水平 recyclerview 滚动然后我滑动以听到对讲时,焦点将移动到工具栏的第一项。然后我需要遍历所有可见项以到达水平滚动视图滚动项。

这个问题只出现在nestedscrollview 中的recyclerviews 中。

我在布局中的嵌套滚动视图以这种方式添加:

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        //my contents

</androidx.core.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

我在布局中的 recyclerview 以这种方式添加:

<LinearLayout
     android:id="@+id/photosLL"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical">

     <androidx.recyclerview.widget.RecyclerView
          android:id="@+id/photosRV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          tools:listitem="@layout/list_item_photo" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是预期的行为还是问题,如何解决?

android talkback android-recyclerview android-accessibility android-nestedscrollview

5
推荐指数
1
解决办法
698
查看次数

Android EditText字段,如按钮

我正在努力应对一个(似乎是)小事.在我的应用程序中,我有一个有两个EditText字段的活动.

我希望其中一个是normall field(etNormal),而另一个(etButton)的行为更像按钮,所以当你触摸它时,键盘没有显示,而是滑动抽屉被打开.如果打开滑动抽屉,您将按下normall edittext滑动抽屉将隐藏.

如果etButton被点击/触摸打开滑动抽屉,我已经尝试添加OnClickListenerOnTouchListener(不是在相同的尝试)条件和条件,如果不是然后关闭.

结果很奇怪.当它是OnTouchListener测试时更像是切换,所以当我按下一个抽屉打开而另一个关闭时.当谈到OnClickListener时,我需要按两次edtitext来完成操作.

并隐藏在我使用的etButton中的键盘setInputType(InputType.TYPE_NULL);.我也尝试了setEnabled(false);但是我甚至无法点击/触摸它.当前使用的方法的一个缺点是当我将点击从etNormal更改为etButton时,键盘仍然显示并且它不会隐藏.

那么,谁能告诉我我能做些什么来实现我的目标呢?

编辑:

我已经删除了你当前的建议并修改了一些我的代码,但它仍然没有用.

这是我分配OnTouchListener的一部分:

OnTouchListener touchListener = new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent ev) {
                if(v==etButton && ev.getAction()==MotionEvent.ACTION_DOWN) {
                    slidingDrawer.animateOpen();
                }else {
                    slidingDrawer.animateClose();
                }
                return false;
            }
        };

        etNormal1.setOnTouchListener(touchListener);
        etNormal2.setOnTouchListener(touchListener);
        etButton.setOnTouchListener(touchListener);
Run Code Online (Sandbox Code Playgroud)

另外在XML布局文件中的etButton声明中我有:

android:focusable="false"
Run Code Online (Sandbox Code Playgroud)

但现在,在etButton触摸没有任何东西(只有滑动抽屉隐藏,如果被打开),当触摸etNormal1或2滑动抽屉显示或隐藏取决于什么是第一(换句话说toggel).

有什么想法,这里有什么不对?

android android-edittext

1
推荐指数
1
解决办法
1788
查看次数