从设置的EditText聚焦停止滚动型EditText

2023-09-04 02:50:35 作者:抢钱抢粮抢娘们

Android的滚动型(滚动或fling'd时),喜欢设定一个EditText的焦点时,它的它的一个孩子。当您滚动,然后再释放它发生。反正是有停止这种行为呢?我已经试过几乎所有我能想到的一切我读过的计算器。什么都没有为我工作。下面就是一个例子布局如果你想测试一下。我不顾一切地阻止这种愚蠢的行为。

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
>

<滚动型
    机器人:ID =@ + ID /滚动视图
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >

<的LinearLayout
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:layout_marginRight =50dp
    机器人:可聚焦=真
    机器人:focusableInTouchMode =真
    >

    <的EditText
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =100dp
        机器人:文本=TestApp 1
        />


    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TestApp 1
        />

    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TestApp 1
        />

    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TestApp 1
        />

    <的EditText
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =100dp
        机器人:文本=的Bleh ......
        />

    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TestApp 1
        />
    <的EditText
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =100dp
        机器人:文本=TestApp 1
        />


    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TestApp 1
        />

    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=MeeEEEEEEEEEEEEE
        />

    <按钮
        机器人:ID =@ + ID / BTN。
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TestApp 1
        />



< / LinearLayout中>
< /滚动型>

< / LinearLayout中>
 

解决方案

这工作。不知道这是否是最好的解决办法还是不行。

  //滚动视图HACK
    // 虚假
    滚动型视图=(滚动型)findViewById(R.id.scrollView);
    view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    view.setFocusable(真正的);
    view.setFocusableInTouchMode(真正的);
    view.setOnTouchListener(新View.OnTouchListener(){
        @覆盖
        公共布尔onTouch(视图V,MotionEvent事件){
            v.requestFocusFromTouch();
            返回false;
        }
    });
 

Flash制作多张图片圆柱形循环滚动效果

Android's ScrollView (when scrolled or fling'd) likes to set the focus of an EditText when it's one of it's children. It happens when you scroll and then release. Is there anyway to stop this behavior? I've tried nearly everything I can think of and everything I've read on StackOverflow. Nothing has worked for me. Below is an example layout If you'd like to test it out. I'm desperate to stop this dumb behavior.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<ScrollView 
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginRight="50dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    >

    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="100dp" 
        android:text="TestApp 1"
        />


    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="100dp" 
        android:text="Bleh...."
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />
    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="100dp" 
        android:text="TestApp 1"
        />


    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="MeeEEEEEEEEEEEEE"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />



</LinearLayout>
</ScrollView>

</LinearLayout>

解决方案

This works. Not sure if it's the best solution or not.

// SCROLL VIEW HACK
    // BOGUS
    ScrollView view = (ScrollView)findViewById(R.id.scrollView);
    view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });

相关推荐