滚动编辑框里面滚动视图 [英] Scrolling editbox inside scrollview
问题描述
我有一个棘手的问题。我在编辑框中(8线)内滚动视图。而当我试图滚动编辑文本的文本它的行为并不稳定。有时,它的滚动,有些时候它没有采取的焦点。
I have a nasty problem. I'm having edit box(8 lines) inside scrollview. And when I'm trying to scroll text in edit text it's behavior is not stable. Sometimes it's scrolling, some times it's not taking focus.
这是我的布局文件,使我的问题更清楚:
This is my layout file, to make my question more clear:
<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>
据我所知,我有,因为里面拿着一个又一个滚动控制这个问题,但我不知道该怎么做与此有关。所以,请帮助我,如果你能。
I understand that I'm having this issue because of holding one scrollable control inside another, yet I don't know what to do with this. So, please help me if you can.
在此先感谢。
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");
}
我想这一点,并没有结果。我仍然无法滚动我的编辑框。
I've tried this, and no result. I'm still unable to scroll my editbox.
推荐答案
尝试:
@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");
}
}
这篇关于滚动编辑框里面滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!