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