2015-06-07 34 views
-5

我想做一個四功能計算器應用程序。兩條空行是計算中涉及的數字。我遇到的問題是'結果'框。由於我使用了relativelayout,因此所有內容都與「結果」框相關。如果我第一次計算,比如說2 + 2,'結果'是4,那沒關係。但是如果我做5 + 5和'結果'現在是10,一個兩位數的數字,所有事情都會因爲'結果'的改變而有所變化。有沒有辦法讓'結果'改變尺寸,但保持其他一切到位?Android預防框調整大小

Picture of current app UI

+1

請向我們展示您當前的xml! – stkent

+0

here,imgur links – Sygnerical

+1

將其編輯到原始問題:) – stkent

回答

1

所以你可以不使用相對佈局。 但是我們可以使用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> 
+0

我從其他堆棧溢出問題中讀到的一件事是,由於市場上衆多的Android設備,建議使用RelativeLayout,並且它會根據設備而改變。 TableLayout是否也適用於不同的設備? – Sygnerical

+0

對不起,我是一個菜鳥,所以我不能發佈圖片。但我已經嘗試過這種佈局在Android Studio上的不同尺寸的屏幕上(包括Nexus one,Nexus s,Nexus 4,5,6), t會根據設備而改變。 – jevirs

+0

好吧,我會檢查出來的謝謝 – Sygnerical