2012-06-20 12 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> 

をしかし、私は戻るボタンを入力する複数行に何かを書くたら私が得るすべては1つの長くなりますラインのEditTextとスクロール可能です。 私は回線番号を設定することができますが、この場合は別のデバイスで動作するはずです。

デバイスの高さをどのように強制することができますか?

ヒント?あなたはコードでそれを追加することができた場合

答えて

2

は(ScrollViewなし)を使用してください:この設定をJavaコードで

<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を持っているとしていることを意味します。 lLayoutです(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> 

.....

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> 
関連する問題