滚动型禁用焦点移到 [英] ScrollView disable focus move

查看:345
本文介绍了滚动型禁用焦点移到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 我有简单的输入形式,它与内滚动型EditTexts垂直LinearLayot。

Hello I have simple input form, it's vertical LinearLayot with EditTexts inside ScrollView.

<ScrollView android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">
            <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:padding="10dip"
                  android:gravity="center_vertical"
                  android:orientation="horizontal">
                  <TextView style="@style/Text"
                         android:text="Name"/>
                  <EditText style="@style/EditBox"/>
            </LinearLayout>
            <View style="@style/Divider"/>
            <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:padding="10dip"
                  android:gravity="center_vertical"
                  android:orientation="horizontal">
                  <TextView style="@style/Text"
                         android:text="Password"/>
                  <EditText style="@style/EditBox"/>
            </LinearLayout>               
            ... 
     </LinearLayout>
</ScrollView>

当用户滚动形成,它会自动将焦点移动到可见的EditText。 它可以禁止这种行为,并始终保持专注的EditText选择触摸?

When user scrolls form, it automatically move focus to visible EditText. It is possible to disable such behavior and always keep focus on EditText selected by touch?

据我所知,这可能是它的一个特点,但我需要禁用它。

I understand, that may be it is a feature, but I need to disable it.

谢谢!

推荐答案

只是想我会分享我解决这个。尽管其他一些答案的评论状态,你不能覆盖这个行为,这是不正确的。这种行为一旦你覆盖 onRequestFocusInDescendants()方法停止。所以,简单地创建滚动型的扩展要做到这一点:

Just thought I'd share my solution to this. Even though some of the other answer's comments state that you cannot override this behavior, that is not true. This behavior stops as soon as you override the onRequestFocusInDescendants() method. So simply create your ScrollView extension to do this:

public class NonFocusingScrollView extends ScrollView {

  public NonFocusingScrollView(Context context) {
    super(context);
  }

  public NonFocusingScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public NonFocusingScrollView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  @Override
  protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    return true;
  }

}

和你就大功告成了。该滚动型会惹你的注意力不动了。

And you're done. The ScrollView will mess with your focus no more.

这篇关于滚动型禁用焦点移到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆