垂直scrollview无法使用光标滚动浏览edittext

问题描述 投票:1回答:2

我有一个垂直滚动视图,其中包含几个单行编辑文本。

我的布局只是风景。

我无法滚动滚动视图超出包含光标的edittext。

如果我更改了包含光标的edittext,我可以滚动直到该edittext到达屏幕的顶部或底部边缘。

可以接收光标/焦点的此活动的唯一控件是scrollview中的edittexts。设置它们没有焦点修复了滚动问题,但显然我不能输入任何值。

请告知我该如何解决这个问题?

由于这种布局的复杂性,我只列出了scrollview部分:

     <LinearLayout android:id="@+id/LinearLayoutRight" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="37" android:orientation="vertical">
    <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="match_parent">
        <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
            <LinearLayout android:id="@+id/counter_pat_section_row1" android:layout_width="match_parent" android:layout_height="108dp" android:layout_marginTop="1dp" android:background="@drawable/shape" android:orientation="vertical">
                <LinearLayout android:id="@+id/LinearLayout05" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="4dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:gravity="right" android:text="Stop at row1" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/white1"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <EditText android:id="@+id/rowmax1" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="1" android:inputType="number" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/resetrow" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@drawable/mybutton" android:gravity="center" android:singleLine="true" android:text="Reset" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/black" android:textSize="8sp"/>
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="5dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/rowcounter" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:text="0" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/white1" android:textSize="44sp"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <Button android:id="@+id/rowup" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:background="@drawable/mybutton" android:gravity="center" android:text="+" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/rowdown" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/mybutton" android:gravity="center_vertical|center_horizontal" android:singleLine="false" android:text="-" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout android:id="@+id/counter_pat_section_row2" android:layout_width="match_parent" android:layout_height="108dp" android:layout_marginTop="1dp" android:background="@drawable/shape" android:orientation="vertical">
                <LinearLayout android:id="@+id/LinearLayout08" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="4dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:gravity="right" android:text="Stop at row2" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/white1"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <EditText android:id="@+id/rowmax2" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="1" android:inputType="number" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout07" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@drawable/mybutton" android:gravity="center" android:singleLine="true" android:text="Reset" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/black" android:textSize="8sp"/>
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout android:id="@+id/LinearLayout06" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="5dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView02" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:text="0" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/white1" android:textSize="44sp"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <Button android:id="@+id/Button03" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:background="@drawable/mybutton" android:gravity="center" android:text="+" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout07" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/Button02" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/mybutton" android:gravity="center_vertical|center_horizontal" android:singleLine="false" android:text="-" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout android:id="@+id/counter_pat_section_row3" android:layout_width="match_parent" android:layout_height="108dp" android:layout_marginTop="1dp" android:background="@drawable/shape" android:orientation="vertical">
                <LinearLayout android:id="@+id/LinearLayout09" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="4dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView06" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:gravity="right" android:text="Stop at row3" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/white1"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <EditText android:id="@+id/rowmax3" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="1" android:inputType="number" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout11" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/Button05" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@drawable/mybutton" android:gravity="center" android:singleLine="true" android:text="Reset" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/black" android:textSize="8sp"/>
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout android:id="@+id/LinearLayout12" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="5dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView05" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:text="0" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/white1" android:textSize="44sp"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <Button android:id="@+id/Button04" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:background="@drawable/mybutton" android:gravity="center" android:text="+" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout11" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/Button06" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/mybutton" android:gravity="center_vertical|center_horizontal" android:singleLine="false" android:text="-" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout android:id="@+id/counter_pat_section_row4" android:layout_width="match_parent" android:layout_height="108dp" android:layout_marginTop="1dp" android:background="@drawable/shape" android:orientation="vertical">
                <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="4dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView07" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:gravity="right" android:text="Stop at row4" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/white1"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <EditText android:id="@+id/rowmax4" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="1" android:inputType="number" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout14" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/Button07" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@drawable/mybutton" android:gravity="center" android:singleLine="true" android:text="Reset" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/black" android:textSize="8sp"/>
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout android:id="@+id/LinearLayout13" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="5dp" android:layout_weight="1">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView08" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:text="0" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/white1" android:textSize="44sp"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <Button android:id="@+id/Button09" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:background="@drawable/mybutton" android:gravity="center" android:text="+" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout14" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/Button08" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/mybutton" android:gravity="center_vertical|center_horizontal" android:singleLine="false" android:text="-" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout android:id="@+id/counter_pat_section_repeat" android:layout_width="match_parent" android:layout_height="108dp" android:layout_marginTop="1dp" android:background="@drawable/shape" android:orientation="vertical">
                <LinearLayout android:id="@+id/LinearLayout04" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="4dp" android:layout_weight="1" android:weightSum="10">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/TextView03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="2dp" android:gravity="right" android:singleLine="false" android:text="Stop at repeat" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/white1"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <EditText android:id="@+id/repeatmax" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_gravity="center_vertical" android:layout_marginRight="3dp" android:layout_weight="1" android:inputType="number" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/black">
                            <requestFocus />
                        </EditText>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/resetrepeat" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@drawable/mybutton" android:singleLine="true" android:text="Reset" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/black" android:textSize="8sp"/>
                    </LinearLayout>
                </LinearLayout>
                <LinearLayout android:id="@+id/LinearLayout03" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="5dp" android:layout_weight="1" android:weightSum="10">
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginLeft="4dp" android:layout_weight="5">
                        <TextView android:id="@+id/repeatcounter" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:text="0" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/white1" android:textSize="44sp"/>
                    </LinearLayout>
                    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="3">
                        <Button android:id="@+id/repeatup" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="right" android:layout_marginRight="3dp" android:layout_weight="1" android:background="@drawable/mybutton" android:text="+" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                    <LinearLayout android:id="@+id/LinearLayout1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="3dp" android:layout_weight="2" android:gravity="center_vertical" android:orientation="vertical">
                        <Button android:id="@+id/repeatdown" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/mybutton" android:gravity="center" android:text="-" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black"/>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout android:id="@+id/counter_pat_section_checkbox" android:layout_width="match_parent" android:layout_height="40dp">
                <CheckBox android:id="@+id/linkcounters" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:text="Link Counts" android:textColor="@color/white1" android:textSize="10sp"/>
                <CheckBox android:id="@+id/screenon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:text="Keep Awake" android:textColor="@color/white1" android:textSize="10sp"/>
                <CheckBox android:id="@+id/soundon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:singleLine="false" android:text="\u266A" android:textColor="@color/white1" android:textSize="16sp"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
android android-edittext scrollview
2个回答
1
投票

这是我的黑客运作良好....

    sv = (ScrollView) this.findViewById(R.id.counter_pat_scrollview);
    sv.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    sv.setFocusable(true);
    sv.setFocusableInTouchMode(true);
    sv.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (rowmax1.hasFocus()) { rowmax1.clearFocus(); }
            if (rowmax2.hasFocus()) { rowmax2.clearFocus(); }
            if (rowmax3.hasFocus()) { rowmax3.clearFocus(); }
            if (rowmax4.hasFocus()) { rowmax4.clearFocus(); }
            return false;
        }
    });

在此示例中,rowmax1,2,3等是EditText。

然后,当视图的高度较大(垂直滚动视图)时,滚动视图可以滚动超出屏幕边界,而scrollview包含edittexts。

并且它不会阻止用户按下edittext并获得软键盘。

希望这最终会帮助别人......如果可以的话请记住我吗?


0
投票

我已经发现layout_weight让edittext像那样行为不端。我刚刚停止使用此参数,直到有关于处理案例的额外信息。

© www.soinside.com 2019 - 2024. All rights reserved.