滚动视图内的编辑文本不可滚动

时间:2014-03-02 14:07:26

标签: android xml android-layout android-edittext scrollview

我已经搜索了解决方案,但似乎这些都没有用。我的情况不适用于更换xml吗?如何解决问题?滚动视图工作但edittext无法正常工作。感谢

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/share_bg" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:overScrollMode="never" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/photo_area"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/share_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/photo_area"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="@string/share_title"
                android:textColor="@android:color/white" />

            <EditText
                android:id="@+id/share_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/share_title"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/custom_textarea"
                android:gravity="top|left"
                android:lines="5"
                android:scrollbars="vertical"
                android:text="@string/default_msg" >

                <requestFocus />
            </EditText>

            <ImageView
                android:id="@+id/share_submit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/share_content"
                android:layout_centerHorizontal="true"
                android:src="@drawable/photo_taken_btn_submit" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

id:share_content是editText,谢谢

1 个答案:

答案 0 :(得分:17)

您可以执行此操作以使edittext可滚动:

 EditText EtOne = (EditText) findViewById(R.id.comment1);
EtOne.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (v.getId() == R.id.comment1) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_UP:
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                        break;
                    }
                }
                return false;
            }
        });

请参阅“Scrolling editbox inside scrollview