android – 在ScrollView中滚动EditText

我有一个讨厌的问题.我在ScrollView中有EditText(8行).当我试图在EditText中滚动文本时,它的行为不稳定.有时它会滚动,有时它不会聚焦.

这是我的布局文件,让我的问题更清晰:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp" >

    <TextView
        android:id="@+id/wo_task_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_description" />

    <TextView
        android:id="@+id/wo_task_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_description" />

    <TextView
        android:id="@+id/wo_task_comments_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="@string/comments" />

    <Button
        android:id="@+id/wo_task_select_comment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/select_comment_from_template" />

    <EditText
        android:id="@+id/wo_task_comments"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="top|left"
        android:hint="@string/enter_your_comment_here"
        android:lines="8"
        android:maxLines="10"
        android:minLines="6"
        android:scrollbars="vertical"
        android:singleLine="false" />
</LinearLayout>

我知道我有这个问题,因为在另一个内部有一个可滚动的控件,但我不知道该怎么办.所以,如果可以,请帮助我.

提前致谢.

public void initComments(final View view) {
    EditText comment = (EditText) view.findViewById(R.id.wo_task_comments);

    comment.setonTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(final View v,final MotionEvent motionEvent) {
            if (view.getId() == R.id.wo_task_comments) {
                view.getParent().requestdisallowInterceptTouchEvent(true);
                switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_UP:
                    view.getParent().requestdisallowInterceptTouchEvent(
                            false);
                    break;
                }
            }
            return false;
        }
    });

    comment.setText(currentTask.getComment() + "very very long comment"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment");
}

我试过这个,没有结果.我仍然无法滚动我的编辑框.

解决方法

尝试:
@Override
public void onCreate(Bundle savedInstanceState) {
    .....  
    EditText et = (EditText)findViewById(R.id.wo_task_comments);
    et.setonTouchListener(this);
    .....
}

@Override
public boolean onTouch(View view,MotionEvent motionEvent) {
    if(view.getId() == R.id.wo_task_comments){
        view.getParent().requestdisallowInterceptTouchEvent(true);
        switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_UP:
                view.getParent().requestdisallowInterceptTouchEvent(false);
                break;
        }
    }
    return false;
}

在你的情况下:

public class MyActivity extends Activity  {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initComments(findViewById(R.id.YOUR_MAIN_LAYOUT_ID));  
}


public void initComments(final View view) {
    EditText comment = (EditText) view.findViewById(R.id.wo_task_comments);

    comment.setonTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(final View v,final MotionEvent motionEvent) {
            if (v.getId() == R.id.wo_task_comments) {
                v.getParent().requestdisallowInterceptTouchEvent(true);
                switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_UP:
                        v.getParent().requestdisallowInterceptTouchEvent(
                                false);
                        break;
                }
            }
            return false;
        }
    });

    comment.setText("very very long comment"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment\n" + "very very long comment\n"
            + "very very long comment");
}

}

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...