2012-12-06 127 views
0

我正在使用計算器,在「屏幕」左側顯示符號+ - * /,右側顯示數字。符號的大小不能太小,但是當用戶按下符號並且符號顯示例如+,右邊的數字會稍微向右移動以符合符號。android layout:edittext右移和左移

當沒有符號時,右邊的數字在有符號的時候繼續向右移動。此外,該符號無法正確顯示。這令人沮喪。

但是我想保留這個符號和數字應該保持在1行內,這樣看起來就像計算器。這怎麼處理?佈局代碼如下。提前致謝!!!!

enter image description here

<TableRow 
    android:id="@+id/tableRow3" 
    android:layout_weight="0.1" 
    android:background="@android:color/white" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" > 


    <EditText 
     android:id="@+id/symEditText" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="left" 
     android:layout_span="1" 
     android:background="@android:color/transparent" 
     android:clickable="false" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:gravity="right|center_vertical" 
     android:inputType="numberDecimal" 
     android:longClickable="false" 
     android:maxLength="3" 
     android:paddingRight="0dp" 
     android:text="" 
     android:textColor="#003366" 
     android:textSize="14dp" 
     android:textStyle="bold" > 

    </EditText> 

    <EditText 
     android:id="@+id/ansEditText" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="right" 
     android:layout_span="9" 
     android:background="@android:color/transparent" 
     android:clickable="false" 
     android:ems="4" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:gravity="right|center_vertical" 
     android:inputType="numberDecimal" 
     android:longClickable="false" 
     android:maxLength="23" 
     android:paddingRight="20dp" 
     android:textColor="#003366" 
     android:textSize="@dimen/display_text_size" 
     android:textStyle="bold" > 

     <requestFocus /> 
    </EditText>   

</TableRow> 
+0

試圖解釋更好發生了什麼,或者甚至更好,提供與當前和期望行爲的一些圖片。 – Luksprog

+0

感謝您的評論。我添加了當前圖像的屏幕截圖。 K無法正確顯示。等待5秒鐘後,它會自動顯示全部K,但右側的數字會向右移動。 – pearmak

回答

0

,才應使用TableRow一個TableLayout內。我想你可以用水平的LinearLayout來代替。如果您希望始終保留顯示符號的空間,請將該視圖固定爲寬度,而不要使用wrap_content,否則當內容更改時它會增大/縮小。 (請確保dp爲單位來指定寬度)

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/symbol" 
     android:layout_width="20dp" <!-- fixed size --> 
     android:layout_height="wrap_content" 
     <!-- more attributes --> 
    </TextView> 

    <TextView 
     android:id="@+id/answer" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" <!-- fill remaining space --> 
     android:gravity="right" 
     <!-- more attributes --> 
    </TextView>   
</LinearLayout> 
+0

我已經嘗試過,但它仍然看起來一樣。我甚至設定爲500dp。右側的圖片向右移動很多,在左側留下空白區域,這意味着符號editText正確佔據了空間。然而,K仍然只是顯示一半.. – pearmak

+0

您嘗試設置固定寬度的哪個視圖?我建議爲「k」做這件事。看我的編輯。 – Karakuri

+0

我採取了你的上面,並進一步刪除android:layout_gravity =「左」,然後它正確地顯示全K而不是半K.感謝您的幫助! – pearmak