这是我的布局文件,让我的问题更清晰:
<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");}
我试过这个,没有结果.我仍然无法滚动我的编辑框.
解决方法 尝试:@OverrIDepublic voID onCreate(Bundle savedInstanceState) { ..... EditText et = (EditText)findVIEwByID(R.ID.wo_task_comments); et.setontouchListener(this); .....}@OverrIDepublic 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 {@OverrIDepublic 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 – 在ScrollView中滚动EditText全部内容,希望文章能够帮你解决android – 在ScrollView中滚动EditText所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)