android - 在 ScrollView 和 ViewFlipper 中启用可滚动的 EditText

标签 android android-layout android-edittext scrollview viewflipper

我在 ViewFlipper 中有两个布局,每个布局中都包含 ScrollView。但是,我的 EditText 不起作用,我知道原因是 ScrollView。但是,尽管我尝试了 Disable ScrollView action 中的答案,没有一个对我有用。我的 xml 哪里有问题吗?我的 xml 如下所示:

翻页器

<?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>

第1页

<?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" />

最佳答案

主要 Activity 类:

您可以通过以下方式执行此操作,还可以看到此 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;
                }
            });

关于android - 在 ScrollView 和 ViewFlipper 中启用可滚动的 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13812892/

相关文章:

android - 两个 View 都可以在Android中获得焦点吗

android - 处理 EditText 上的 Enter 键(Kotlin,Android)

java - 将 SQLite 条目打印到 ListView 中

android - ViewPager OnPageSelected() 或 OnPageShow() 中的 fragment ?

android - 在两种布局颜色之间反复翻转

Android 谷歌地图 - 从 FAB 菜单选择 map 类型

android - 如何将带有高亮颜色背景的文本添加到 ImageView

android - EditText.getText() 是否曾经返回 null?

android - 由于其他不需要的输出淹没 logcat,我的应用程序的 logcat 输出不断消失

android - 合并多个版本号的布局文件