我有一個表格佈局,前兩行有2個EditText,一排按鈕在其他行中像自定義鍵盤一樣工作。 (爲簡單起見,只包含下面xml中的第一行按鈕) EditText視圖設置爲可滾動使用android:scrollbars="vertical"
。當我按下我的自定義鍵盤上的按鈕,我將值添加到輸入字符串,然後我用EditText.setText()
方法設置文本。我的問題是,如果文本太長,它會進入下一行,調整整個EditText視圖的大小。否則,使用默認的安卓鍵盤就像魅力一樣,在下一行顯示右側的滾動條。
這裏的XMLEditText視圖使用「setText」而不是鍵盤輸入時調整大小
<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調整大小。
任何建議,可以理解
添加所需的輸出圖片 –