Android scrollView.requestFocus()返回true,但不起作用

Android scrollView.requestFocus()返回true,但不起作用,android,android-layout,Android,Android Layout,总之,我有一个包含编辑文本的卷轴 一旦我点击编辑文本,它就会获得焦点并显示一个软输入 在我的脑海中,如果单击空白空间,StuttPosieHead和EddiTeX失去焦点,ScLoVIEW获取焦点。 我的代码是这样的: scrollView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) {

总之,我有一个包含编辑文本的卷轴

一旦我点击编辑文本,它就会获得焦点并显示一个软输入

在我的脑海中,如果单击空白空间,StuttPosieHead和EddiTeX失去焦点,ScLoVIEW获取焦点。

我的代码是这样的:

scrollView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //call twice, once down, once up
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null) {
                    inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                    scrollView.requestFocus();
                    activity.getCurrentFocus();
                }
            }
            return false;
        }
    });



ScrollView
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:id="@+id/scrollView"
        android:layout_below="@+id/topBar"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

但毕竟,editText仍然是焦点(activity.getCurrentFocus()==editText),有什么建议吗?

使用LinearLayout而不是ScrollView。或者使用下面的LinearLayout将编辑文本换行

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:layout_gravity="center_horizontal" >

    <LinearLayout
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/linearLayout"
        android:layout_gravity="center_horizontal" >

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"
            android:ems="10"
            android:id="@+id/editText" />
    </LinearLayout>
</ScrollView>


通过编程从编辑文本中删除焦点。@MurtazaHussain我使用“activity.getCurrentFocus().clearFocus();”,还是什么都没发生你能说明你的问题是什么吗?您的代码表现如何?您期望得到什么?