سؤال

I need a EditText that fills in height my window. I'm using this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >

<EditText
    android:id="@+id/text_editor"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:gravity="top|left"
    android:inputType="textMultiLine"
    android:textColor="@android:color/white" />

</ScrollView>

But all I get is a one line EditText that will be longer and scrollable once I write something on multiline typing the return button. I know I can set the line number, but in this case it should work on different devices and every device (I guess) has different amount of lines.

How can I force it to fill the device in height?

Any tips?

هل كانت مفيدة؟

المحلول

Try to use (without ScrollView):

<EditText
    android:id="@+id/text_editor"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:gravity="top|left"
    android:textColor="@android:color/white" />

نصائح أخرى

Try setting this for EditText, I had the same thing, this will work.

<EditText
android:id="@+id/text_editor"
android:layout_width="match_parent"
**android:layout_height="wrap_content"**
android:background="#ff0000"
android:gravity="top|left"
android:inputType="textMultiLine"
android:textColor="@android:color/white" />

and you can also use this one to set exactly how many lines you need,

android:lines="number of Lines"
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <EditText
        android:id="@+id/editText1"
        android:scrollbars="vertical" <-----------
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:gravity="top|left"
        android:ems="10"
        android:text=" example text" />

</RelativeLayout>

in java code set this.....

ed1 = (EditText) findViewById(R.id.editText1);
ed1.setMovementMethod(new ScrollingMovementMethod()); <--------

Will work in all device.

Hope this will help you.

My Code it's Work for me.

<?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:background="#ffffff"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView20"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/img_desc1"
    android:src="@drawable/num74_head_payakorn" />

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <EditText
        android:id="@+id/edtPayakorn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="22sp"
        android:clickable="false"
        android:cursorVisible="false"
        android:editable="false"
        android:enabled="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="top|left"
        android:scrollbars="vertical"
        android:inputType="textMultiLine" />
    </TableRow>
</LinearLayout>

If you can add it in the code it would be like this:

EditText et = new EditText(this);
l.addView(et, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 100));

where the 100 means it is going to have 100dp of width. the l is the Layout you may have (ScrollView in your case) which you can get with R.layout.name_of_the_scroll_view.

I'm not sure but try to put in the property of height the WRAP_CONTENT.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top