如何在滚动视图内滚动编辑文本 [英] How to scroll the edittext inside the scrollview

查看:27
本文介绍了如何在滚动视图内滚动编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图,里面有一个多行的editext.我想滚动编辑文本以查看较低的内容,但无法完成.

I have a scrollview inside which there is a editext which is multiline. I want to scroll the edittext to see the lower content but it can't be done.

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

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

Can you guys help me in that . I think editText is getting the focus when cursor is inside it.

谢谢..!!!!!!

推荐答案

试试这个..

将以下几行添加到您的 EditText

Add below lines into your 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;
       }
});

这篇关于如何在滚动视图内滚动编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆