相关疑难解决方法(0)

有没有办法以编程方式将滚动视图滚动到特定的编辑文本?

我有一个很长的活动与scrollview.这是一个包含用户必须填写的各种字段的表单.我的表单中有一个复选框,当用户检查它时,我想滚动到视图的特定部分.有没有办法以编程方式滚动到EditText对象(或任何其他视图对象)?

此外,我知道这可能使用X和Y坐标,但我想避免这样做,因为表单可能会从用户更改为用户.

android view scrollview android-edittext programmatically-created

187
推荐指数
10
解决办法
13万
查看次数

以编程方式滚动到NestedScrollView的顶部

有没有办法以编程方式滚动到顶部NestedScrollView还通过触发父级的滚动事件?smoothScrollTo(x, y)不会将滚动事件委托给NestedScrollingParent.

android android-layout android-nestedscrollview

68
推荐指数
9
解决办法
5万
查看次数

NestedScrollView的fullScroll(View.FOCUS_UP)无法正常工作

我有一个NestedScrollView填充了一个垂直的LinearLayout,它本身有一堆各种视图类型的子项:多个TextViews,两个静态GridViews,甚至一个FrameLayout来显示所有这些下面的片段.

当按下后退按钮时,如果用户滚动到某个点以下,而不是完成活动,则调用"scrollToTop"方法:

public static void scrollToTop(final NestedScrollView scrollview) {
    new Handler().postDelayed(new Runnable() {
        public void run() {
            scrollview.fullScroll(NestedScrollView.FOCUS_UP);
        }
    }, 200);
}
Run Code Online (Sandbox Code Playgroud)

这适用于我的应用程序的早期版本,该版本位于Play商店中.但现在,在更新我的应用程序以定位Android Oreo(并将支持库更新到版本26.0.2)之后,它似乎从NestedScrollView的原始滚动位置下方开始滚动,而不是滚动到顶部,并停止它的位置.所以它只是看起来像一个奇怪的口吃.然而,在某些位置,它确实滚动到顶部(尽管非常罕见且不一致),而其他位置实际上滚动到底部,出于什么原因我不明白.

我一直在试验视图的可聚焦性,但无济于事.例如,我读到静态GridViews可能会在滚动时中断焦点.我也尝试了各种不同的方法来向上滚动,例如

scrollview.pageScroll(View.FOCUS_UP);
Run Code Online (Sandbox Code Playgroud)

scrollview.smoothScrollTo(0,0);
Run Code Online (Sandbox Code Playgroud)

但似乎没有任何效果.这次支持库有什么问题吗?

android android-nestedscrollview

11
推荐指数
3
解决办法
4225
查看次数

smoothScrollToPosition在嵌套的RecyclerView中不起作用

我有一个recyclerView,每个项目都是一个recyclerView。我想在特定条件下滚动到内部recyclerView的自定义位置。我在innerRecyclerView上使用了这段代码,但是没有用:

innerRecyclerView.smoothScrollToPosition(position); 
Run Code Online (Sandbox Code Playgroud)

和这个:

innerRecyclerView.scrollToPosition(position); 
Run Code Online (Sandbox Code Playgroud)

还有这个:

layoutManager.scrollToPositionWithOffset(position, offset);
Run Code Online (Sandbox Code Playgroud)

现在我有两个问题:

1)是否可以滚动到内部recyclerView的自定义位置?

2)如果可能的话,怎么办?

这是初始化主recyclerView:

LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false);
        adapter = new FreightsListRVAdapter(new FreightListCallBack(), new FreightListVHFactory());
        rvFreightsList.setLayoutManager(layoutManager);
        rvFreightsList.setItemViewCacheSize(30);
        rvFreightsList.setNestedScrollingEnabled(true);
        rvFreightsList.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

这是初始化innerRecyclerview:

LinearLayoutManager layoutManager = new LinearLayoutManager(itemView.getContext(), RecyclerView.VERTICAL, false);
        layoutManager.setItemPrefetchEnabled(true);
        layoutManager.setInitialPrefetchItemCount(7);
        rvFreights.setNestedScrollingEnabled(false);
        rvFreights.setLayoutManager(layoutManager);
        rvFreights.setItemViewCacheSize(20);

        adapter = new FreightsRVAdapter(new FreightCallBack(), new FreightSingleVHFactory());
        rvFreights.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

这是我的主要recyclerView适配器:

public class FreightsListRVAdapter extends ListAdapter<FreightListModel, FreightListVH> {

    private final FreightListVHFactory mFactory;
    private final PublishSubject<FreightListVHAction> mClickUserPS = PublishSubject.create();

    @Inject
    public FreightsListRVAdapter(@NonNull FreightListCallBack diffCallback, FreightListVHFactory factory) {
        super(diffCallback);
        mFactory = factory; …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview nestedrecyclerview

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