<LinearLayout xmlns:android="..."
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/tvResult" ... />
<GridLayout
android:id="@+id/gridKeys"
android:columnCount="4"
android:rowCount="5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- 按鈕由代碼動態添加或 XML 定義 -->
</GridLayout>
</LinearLayout>
operand1, operator, waitingForOperand 狀態BigDecimal 避免浮點誤差binding.gridKeys.setOnClickListener(v -> {
String tag = (String) v.getTag();
if ("0123456789.".contains(tag)) appendDigit(tag);
else if ("+-*/".contains(tag)) setOperator(tag);
else if ("=".equals(tag)) calculate();
else if ("C".equals(tag)) clear();
});
支持連續運算、括號、百分比、科學計算模式可擴展為表達式解析器(Shunting-yard 算法)。