Enable Scrollable EditText within a ScrollView and ViewFlipper

别来无恙 提交于 2019-11-27 08:06:45

问题


I have a two layout in a ViewFlipper which contains ScrollView in each of the layout. However, my EditText does not work and I know the reason is due to the ScrollView. However, though I tried the answers in Disable ScrollView action , none worked for me. Is there a problem with my xml some where? My xml is such shown below:

PageFlipper

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

<!-- Header -->

<include
    android:id="@+id/include1"
    layout="@layout/prepostheader" />

    <RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:background="#FFF"
    android:orientation="vertical">

<Button
    android:id="@+id/btnPage2"
    style="@style/PageBtnFont"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/include1"
    android:layout_marginTop="2dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/button"
    android:text="Page 2" />

<Button
    android:id="@+id/btnPage1"
    style="@style/PageBtnFont"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btnPage2"
    android:layout_alignBottom="@+id/btnPage2"
    android:layout_toLeftOf="@+id/btnPage2"
    android:layout_marginRight="5dp"
    android:background="@drawable/button"
    android:text="Page 1" />
</RelativeLayout>


<ViewFlipper
    android:id="@+id/flipper" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">        


    <include layout="@layout/prepostform" 
        android:adjustViewBounds="true"/>
    <include layout="@layout/prepostform2" 
        android:adjustViewBounds="true"/>

</ViewFlipper>

Page1

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/editFormLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
android:orientation="vertical" >

<ScrollView
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView"
    android:layout_weight="1"
    android:padding="5px">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:src="@drawable/formprepost" />



<EditText
    android:id="@+id/name"
    android:layout_width="400dp"
    android:layout_height="35dp"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/include1"
    android:layout_marginRight="90dp"
    android:layout_marginTop="134dp"
    android:background="#0000"
    android:ellipsize="start"
    android:inputType="textCapWords|textPersonName"
    android:lines="1"
    android:maxLines="1"
    android:textAppearance="@style/TextStyle1" >

</EditText>

<EditText
    android:id="@+id/school"
    android:layout_width="400dp"
    android:layout_height="35dp"
    android:layout_marginTop="-8dp"
    android:layout_alignLeft="@+id/name"
    android:inputType="textCapWords|textPersonName"
    android:background="#0000"
    android:textAppearance="@style/TextStyle1"
    android:ellipsize="start"
    android:maxLines = "1"
    android:lines = "1"
    android:layout_below="@+id/name" />

<EditText
    android:id="@+id/supervisor"
    android:layout_width="400dp"
    android:layout_height="35dp"
    android:layout_marginTop="-9dp"
    android:layout_alignLeft="@+id/school"
    android:inputType="textCapWords|textPersonName"
    android:background="#0000"
    android:textAppearance="@style/TextStyle1"
    android:ellipsize="start"
    android:maxLines = "1"
    android:lines = "1"
    android:layout_below="@+id/school" />

<EditText
    android:id="@+id/date"
    android:layout_width="200dp"
    android:layout_height="35dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/supervisor"
    android:layout_marginLeft="185dp"
    android:inputType="textCapWords|textPersonName"
    android:textAppearance="@style/TextStyle1"
    android:background="#0000"
    android:ellipsize="start"
    android:maxLines="1"
    android:layout_marginTop="116dp">
</EditText>

<CheckBox
    android:id="@+id/tick1"
    android:layout_width="540dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:button="@drawable/checkbox_selector"
    android:layout_below="@+id/date"
    android:layout_marginLeft="154dp"
    android:layout_marginTop="43dp"/>

<CheckBox
    android:id="@+id/tick2"
    android:layout_width="240dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="-11dp"
    android:layout_alignLeft="@+id/tick1"
    android:button="@drawable/checkbox_selector"
    android:layout_below="@+id/tick1"/>

<CheckBox
    android:id="@+id/tick3"
    android:layout_width="270dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tick2"
    android:layout_marginTop="-12dp"
    android:button="@drawable/checkbox_selector"
    android:layout_below="@+id/tick2" />




<EditText
    android:id="@+id/comment1"
    android:layout_width="614dp"
    android:layout_height="180dp"
    android:layout_alignParentLeft="true"
    android:layout_alignRight="@+id/tick1"
    android:layout_below="@+id/tick3"
    android:layout_marginLeft="94dp"
    android:layout_marginTop="23dp"
    android:gravity="top|left"
    android:inputType="textCapSentences|textMultiLine"
    android:textAppearance="@style/TextStyle1" >

</EditText>

<EditText
    android:id="@+id/comment2"
    android:layout_width="614dp"
    android:layout_height="165dp"
    android:layout_alignLeft="@+id/comment1"
    android:layout_alignRight="@+id/comment1"
    android:layout_below="@+id/comment1"
    android:layout_marginTop="90dp"
    android:gravity="top|left"
    android:inputType="textCapSentences|textMultiLine" />

<ImageButton
    android:id="@+id/signature1"
    android:layout_width="170dp"
    android:layout_height="50dp"
    android:layout_alignLeft="@+id/date"
    android:layout_below="@+id/comment1"
    android:layout_marginLeft="49dp"
    android:background="#0000"/>

<ImageButton
    android:id="@+id/signature2"
    android:layout_width="170dp"
    android:layout_height="50dp"
    android:layout_alignLeft="@+id/supervisor"
    android:layout_below="@+id/comment2"
    android:background="#0000" />


回答1:


Main Actvity Class:

You can Perform this below way and also see this link

 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;
                }
            });


来源:https://stackoverflow.com/questions/13812892/enable-scrollable-edittext-within-a-scrollview-and-viewflipper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!