android - ScrollView 内的可滚动 EditText

标签 android android-layout android-edittext android-scrollview

我搜索了所有关于这个主题的帖子,但仍然找不到任何解决方案。 我有一个大布局,它可以用 ScrollView 滚动,它也有 EditText 和 scrollable 。 如果我尝试滚动 edittext ,布局就会开始滚动。我该如何解决?

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

    <ScrollView
        android:id="@+id/lroot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fillViewport="true"

         >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/img6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:gravity="right"
                android:onClick="runInfo"
                android:src="@drawable/info_btn" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/splash" />

            <!-- Scrollable EditText -->
            <EditText
                android:id="@+id/EditText01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:autoLink="all"
                android:background="@drawable/isim_soyisim"
                android:clickable="true"
                android:cursorVisible="true"
                android:gravity="left|top"
                android:scrollbars="vertical"
                android:inputType="textMultiLine"
                android:longClickable="false"
                android:maxLines="5"
                android:singleLine="false"

            />


        </LinearLayout>
    </ScrollView>

</LinearLayout>

最佳答案

package com.sam.views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class CustomScrollview extends ScrollView{

    public CustomScrollview(Context context) {
        super(context);
    }

     public CustomScrollview(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public CustomScrollview(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action)
        {
            case MotionEvent.ACTION_DOWN:
                    super.onTouchEvent(ev);
                    break;

            case MotionEvent.ACTION_MOVE:
                    return false; // redirect MotionEvents to ourself

            case MotionEvent.ACTION_CANCEL:
                    super.onTouchEvent(ev);
                    break;

            case MotionEvent.ACTION_UP:
                    return false;

            default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
        }

        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        super.onTouchEvent(ev);
         return true;
    }
}

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

相关文章:

java - MaskedEditText 无法获取文本

java - 如何从 Java (Android) 中的 XML 节点获取标记 'Name'

Android:在 fragment 之间传递一个 JSONobject

Android 分隔线颜色 DatePicker 对话框

android - 限制用户在编辑文本中输入 1 个十进制值

android - 方向更改后如何将光标移动到 EditText 行的末尾?

java - 根据空格分割字符串

java - Android 监听器在 Activity 中工作,但不在 Fragment 中工作

android - 自定义通知布局不覆盖整个宽度

java - 单击按钮时将文本从 EditText 发送到 TextView,如果选中单选按钮/复选框,则添加格式