2017-02-09 5 views
0

私は最初の2行に2つのEditTextを持つテーブルレイアウトと、他の行のカスタムキーボードのように動作するボタンの束を持っています。 (簡略化のため、xmlの最初の行のボタンだけが含まれています) EditTextビューは、android:scrollbars="vertical"でスクロール可能に設定されています。カスタムキーボードのボタンを押すと、値が入力文字列に追加され、次にEditText.setText()メソッドでテキストが設定されます。私の問題は、テキストが長すぎると、完全なEditTextビューも次の行にリサイズすることです。さもなければ、デフォルトのアンドロイドキーボードで同じことを行うのは、チャームのように機能し、サイズ変更せずに次の行に進み、右側にスクロールバーを表示します。

は、ここでXMLキーボード入力の代わりに "setText"を使用すると、EditTextビューのサイズが変更される

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:scrollbars="vertical" 
      android:layout_height="match_parent" 
      android:id="@+id/input" 
      android:layout_span="2" 
      android:text="Type an expression to begin..." /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" 
      android:id="@+id/output" 
      android:layout_span="2" 
      android:text="Real time calculation"/> 
    </TableRow> 

    <View 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dp" > 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_clear" 
      android:text="C" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_divide" 
      android:text="/" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_multiply" 
      android:text="*" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_delete" 
      android:text="DEL" /> 
    </TableRow> 

</TableLayout> 

setText()方法の問題点は何ですか? さらに、EditTextをサイズ変更しなくても、両方のEditTextに背景画像を追加して、ビューに合わせてサイズを変更したいとします。

任意の提案は、これはあなたの問題を解決する使用

+0

希望の出力画像を追加 –

答えて

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_gravity="center" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:id="@+id/input" 
      android:text="Type an expression to begin...\n\n\n\n\n\n\n\n\n ddfsfs\n\n\n erwr dsf" /> 
    </ScrollView> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:background="#220000" /> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_gravity="center" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:id="@+id/output" 
      android:text="Real time calculation"/> 
    </ScrollView> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <LinearLayout 
     android:id="@+id/tableRow3" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:padding="15dp" 
      android:layout_height="match_parent" 
      android:id="@+id/button_clear" 
      android:text="C" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_divide" 
      android:text="/" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_multiply" 
      android:text="*" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_delete" 
      android:text="DEL" /> 
    </LinearLayout> 

</LinearLayout> 
+0

ありがとうございました。あなたは私の一日を作った。 LinearLayoutのTableLayout instedを使っていない理由を説明できますか? – Razinar

0
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:scrollbars="vertical" 
      android:layout_height="match_parent" 
      android:id="@+id/input" 
      android:layout_span="2" 
      android:maxLines="1" 
      android:lines="1" 
      android:inputType="text" 
      android:text="Type an expression to begin..." /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" 
      android:id="@+id/output" 
      android:layout_span="2" 
      android:maxLines="1" 
      android:lines="1" 
      android:inputType="text" 
      android:text="Real time calculation"/> 
    </TableRow> 

    <View 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dp" > 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_clear" 
      android:text="C" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_divide" 
      android:text="/" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_multiply" 
      android:text="*" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_delete" 
      android:text="DEL" /> 
    </TableRow> 

</TableLayout> 

を理解されるであろう。

関連する問題