Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get scrolling in edittext when it is inside scrollview?

Tags:

android

In my application i am using EditText to write the Mail description and i made it as per following. My edittext has multiple lines. When i am entering more lines and try to move from bottom to up in edittext at that time scrolling of edittext is not working.

Can anybody help me ? Thanks..

<ScrollView
    android:id="@+id/scrollView" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbarStyle="insideOverlay">

            <EditText
                android:id="@+id/edBody"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:lines="5"
                android:scrollbars="vertical"
                android:text="" 
                android:inputType="textMultiLine"/>    


    </ScrollView>
like image 361
Sunil Parmar Avatar asked Dec 26 '11 05:12

Sunil Parmar


People also ask

What is fillViewport in ScrollView?

fillViewport allows scrollView to extend it's height equals to the full height of device screen's height in the cases when the child of scroll view has less height.

Is ScrollView a Viewgroup?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.

How do I scroll up layout when clicking on EditText?

Android EditText not editable but scrollableUse this porperties in your EdittText: android:enabled="true" android:focusableInTouchMode="false" android:scrollbars="vertical". Your EditText will be enable, but not focusable for edit. Then, you will able to scroll (in vertical on this case) and will not able to edit.

Does ListView have scroll?

A ListView in Android is a scrollable list used to display items.


1 Answers

Try this

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
    >
    <EditText
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="Loooooooooonng loooooooooong teeeeeeeeeeext"
        android:id="@+id/et"
        android:maxLines = "100"
        android:scrollbars = "vertical"
        />
</LinearLayout>

MyActivity.java

public class MyActivity extends Activity {
    private EditText et;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        et= (EditText) findViewById(R.id.et);
        et.setMovementMethod(new ScrollingMovementMethod());
    }
}

NOTE: You cannot put scrollable control (for example ListView) in ScrollView. And I think it does not work with scrollable EditText into ScrollView.

like image 170
jimpanzer Avatar answered Oct 05 '22 05:10

jimpanzer