安卓prevent盒调整大小 [英] Android Prevent Box From Resizing
问题描述
我试图让四个功能计算器应用程序。两个空白行是涉及在计算中的数字。这个问题我已经是与结果框。因为我用RelativeLayout的,安置一切是相对于结果框。如果我先计算一下,说,2 + 2'结果'是4,它的确定。但是,如果我做5 + 5'结果'现在是10,一个两位数,一切都转移了一点,因为结果发生了变化。有没有办法让'结果'改变大小,但保持一切到位?
I am trying to make a four function calculator app. The two blank lines are the numbers involved in the calculations. The issue I have is with the 'result' box. Since I used relativelayout, the placement of everything is relative to the 'result' box. If I first calculate, say, 2+2 and 'result' is 4, it's ok. But if I do 5+5 and 'result' is now 10, a two digit number, everything shifts a little because 'result' has changed. Is there a way to let 'result' change size but keep everything else in place?
推荐答案
所以,你可能无法使用相对布局。 但是,我们可以使用TableLayout?
So you may not use Relative Layout. But can we use TableLayout?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_weight="2"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<EditText
android:inputType="number"
android:layout_gravity="bottom"
android:id="@+id/num_1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Space android:layout_weight="1"
android:layout_width="0dp"/>
<EditText
android:inputType="number"
android:layout_gravity="bottom"
android:id="@+id/num_2"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<TextView
android:singleLine="true"
android:text="Result"
android:gravity="center"
android:textSize="24sp"
android:id="@+id/result"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_column="18" />
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<Button
android:text="ADD"
android:id="@+id/add"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"/>
<Space
android:layout_width="0dp"
android:layout_weight="2"
/>
<Button
android:text="SUBTRACT"
android:id="@+id/sub"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<Button
android:text="MULTIPLY"
android:id="@+id/multi"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"/>
<Space
android:layout_width="0dp"
android:layout_weight="2"
/>
<Button
android:text="DIVIDE"
android:id="@+id/divide"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
这篇关于安卓prevent盒调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!