Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

android - How to scroll the edittext inside the scrollview

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>

enter image description here

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

Thanks..!!!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this..

Add below lines into your EditText

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

Example

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

EDIT

Programmatically

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...