2012-06-20 58 views
5

我需要一個EditText來填充窗口的高度。 我使用這個:Android - EditText多行強制填充高度

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

但我得到的是一個行EditText上,這將是較長,滾動一次,我寫上多輸入返回按鈕的東西。 我知道我可以設置行號,但在這種情況下,它應該在不同的設備上工作,每個設備(我猜)都有不同的行數。

我該如何強迫它在高度上填充設備?

任何提示?

回答

2

嘗試使用(不滾動型):

<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" /> 
+0

在沒有滾動視圖的情況下使用確實有幫助。 –

0

如果你可以在代碼中添加它,它會是這樣:

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

其中100意味着它要具有寬的100dp。 l是您可能擁有的Layout(您的情況爲ScrollView),您可以通過R.layout.name_of_the_scroll_view獲得。

我不確定,但嘗試投入高度屬性WRAP_CONTENT

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

在設置這個java代碼.....

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

將在所有設備正常工作。

希望這會幫助你。

2

試着爲EditText設置這個,我有同樣的事情,這將工作。

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

,你也可以用這個來設置你到底有多少不拘一格,

android:lines="number of Lines" 
0

我的代碼是爲我工作。

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