我想做一個四功能計算器應用程序。兩條空行是計算中涉及的數字。我遇到的問題是'結果'框。由於我使用了relativelayout,因此所有內容都與「結果」框相關。如果我第一次計算,比如說2 + 2,'結果'是4,那沒關係。但是如果我做5 + 5和'結果'現在是10,一個兩位數的數字,所有事情都會因爲'結果'的改變而有所變化。有沒有辦法讓'結果'改變尺寸,但保持其他一切到位?Android預防框調整大小
回答
所以你可以不使用相對佈局。 但是我們可以使用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>
我從其他堆棧溢出問題中讀到的一件事是,由於市場上衆多的Android設備,建議使用RelativeLayout,並且它會根據設備而改變。 TableLayout是否也適用於不同的設備? – Sygnerical
對不起,我是一個菜鳥,所以我不能發佈圖片。但我已經嘗試過這種佈局在Android Studio上的不同尺寸的屏幕上(包括Nexus one,Nexus s,Nexus 4,5,6), t會根據設備而改變。 – jevirs
好吧,我會檢查出來的謝謝 – Sygnerical
- 1. Android調整大小的相機預覽
- 2. 防止wx.StaticBitmap調整大小
- 3. wx.PasswordEntryDialog防止調整大小
- 4. 防止表調整大小
- 5. WPF防止datagrid自動調整窗口大小調整大小
- 6. Android調整大小複選框
- 7. Android創建半調整大小的框
- 8. 預防<label></label>從調整大小
- 9. 複選框調整大小
- 10. 調整JDialog框的大小
- 11. 防止調整大小的文本區域調整整個表的大小
- 12. 當文本框調整大小時,窗口大小調整
- 13. 在調整jQuery對話框大小時調整控件大小
- 14. 調整大小Android應用
- 15. Android沒有調整大小?
- 16. 調整大小和Android的
- 17. Android Image調整大小
- 18. android - 調整片段大小
- 19. Android活動調整大小
- 20. Android圖像調整大小
- 21. 在Android中調整大小
- 22. Android調整大小TextView
- 23. 調整Android文字大小
- 24. Android - 自動調整大小
- 25. NSLayoutConstraint防止NSWindow調整大小
- 26. 防止JList自動調整大小
- 27. 防止WPF Datagrid列調整大小
- 28. jQuery的防抖動調整大小
- 29. 防止網站調整大小
- 30. OpenGL防止在窗口調整大小
請向我們展示您當前的xml! – stkent
here,imgur links – Sygnerical
將其編輯到原始問題:) – stkent