本文介绍了Android TabHost在TabChange的侧面ScrollView中自动垂直滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在活动"的ScrollView中使用了TabHost,但是无论何时选择选项卡,它都会自动垂直滚动视图以结束.

I am using TabHost inside ScrollView in my Activity but when ever I select tab it automatically scrolls my view vertically to end.

推荐答案

基于Er Pragati Singh的回答,我没有覆盖requestChildFocus(View child, View focused),而是覆盖了computeScrollDeltaToGetChildRectOnScreen(Rect rect).

Based on Er Pragati Singh's answer I did not override requestChildFocus(View child, View focused) but computeScrollDeltaToGetChildRectOnScreen(Rect rect).

覆盖requestChildFocus还将阻止触摸已具有焦点的EditText时激活屏幕键盘,而computeScrollDeltaToGetChildRectOnScreen仅用于计算requestChildFocus内的增量滚动以使视图可见.因此,重写此功能可以使所有其他例程保持不变.

Overriding requestChildFocus will also prevent activating the on screen keyboard when touching an EditText which already has focus, while computeScrollDeltaToGetChildRectOnScreen is only used to calculate the delta scroll inside requestChildFocus to bring the View in sight. So overriding this function keeps all other routines intact.

Java:

public class MyScrollView extends ScrollView {
    public MyScrollView(Context context) {
        super(context);

    }

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
        // This function calculates the scroll delta to bring the focused view on screen.
        // -> To prevent unsolicited scrolling to the focued view we'll just return 0 here.
        //
        return 0;
    }
}

XML:

<YOUR.PAKAGE.NAME.MyScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
</YOUR.PAKAGE.NAME.MyScrollView>

这篇关于Android TabHost在TabChange的侧面ScrollView中自动垂直滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:11