android - 如何在 ScrollView 中滚动编辑文本

标签 android user-interface scrollview

我有一个 ScrollView ,里面有一个 multiline 的编辑文本。我想滚动edittext来查看下面的内容,但是做不到。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_light"
        android:gravity="center" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="View Complaint"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:padding="20dp" >
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="Order Number 0100C1"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Name of ClientClient 1"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Subject : Measurement Issues"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dp"
                android:text="Description"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="Lorem ipsum dolor sit amet, sapien etiam, nunc amet dolor ac odio mauris justo. Luctus arcu, urna praesent at id quisque ac. Arcu massa vestibulum malesuada, integer vivamus el/ eu "
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:text="Assign to"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <Spinner
                    android:id="@+id/spinner1"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:entries="@array/array_name" />
            </LinearLayout>
            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_marginTop="15dp"
                android:background="#eeeeee"
                android:inputType="textMultiLine"
                android:singleLine="false"
                android:text="Android applications normally run entirely on a single thread by              default the “UI thread” or the “main thread”.
        
            android:textAppearance="?android:attr/textAppearanceMedium" ></EditText>
            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="Comment History"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="fill_parent"
                android:layout_height="147dp"
                android:src="@drawable/adddd" />
            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="Close Complaints"
                android:textAppearance="?android:attr/textAppearanceLarge" />
            <Button
                android:id="@+id/login"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_below="@+id/ll"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/login_btn"
                android:text="Submit"
                android:textColor="@android:color/holo_blue_dark"
                android:textSize="25dp"
                android:textStyle="bold" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

enter image description here

你们能帮我吗?我认为当光标在其中时,editText 正在获得焦点。

谢谢..!!!!!!

最佳答案

试试这个..

将下面的行添加到您的 EditText

android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"

示例

   <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="15dp"
        android:background="#eeeeee"
        android:inputType="textMultiLine"
        android:singleLine="false"
        android:overScrollMode="always"
        android:scrollbarStyle="insideInset"
        android:scrollbars="vertical"
        android:text="Android applications normally run entirely on a single thread by              default the “UI thread” or the “main thread”.
        android:textAppearance="?android:attr/textAppearanceMedium" >
    </EditText>

编辑

以编程方式

youredittext.setOnTouchListener(new OnTouchListener() {

      public boolean onTouch(View v, MotionEvent event) {
            if (youredittext.hasFocus()) {
               v.getParent().requestDisallowInterceptTouchEvent(true);
               switch (event.getAction() & MotionEvent.ACTION_MASK){
               case MotionEvent.ACTION_SCROLL:
                      v.getParent().requestDisallowInterceptTouchEvent(false);
                      return true;
                }
             }
             return false;
       }
});

关于android - 如何在 ScrollView 中滚动编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24428808/

相关文章:

java - 我正在制作游戏,我需要关闭 JOptionPane

android - react native : TouchableOpacity onPress problems inside a ScrollView

android - 在 android 的 ScrollView 中加载数百个位图图像时出现内存不足错误

android - LogCat 窗口无法进入 Eclipse?

android - 无法使用 BroadcastReceiver 捕获 android.intent.action.DELETE

iphone - iPhone SDK 的 Mac OS 中是否存在标签字段或类似标签的内容?

java - gui 应用程序中的异常处理

android - getChildAt(pos) 在 RecyclerView 上返回 null

java - Libgdx:如何删除表格中的边框

javascript - React Native ScrollView - 如何从另一个子组件按钮滚动到子组件?