Android 的Margin和Padding属性以及支持的长度单位

本文详细解释了Android中Margin和Padding的概念及应用,包括它们在布局中的作用,并介绍了Android支持的各种长度单位及其应用场景。

Android的Margin和Padding跟Html的是一样的。如下图所示:黄色部分为Padding,灰色部分为Margin。

image

通俗的理解 Padding 为内边框,Margin 为外边框

对应的属性为

android:layout_marginBottom="25dip" 
android:layout_marginLeft="10dip" 
android:layout_marginTop="10dip" 
android:layout_marginRight="10dip" 
android:paddingLeft="1dip" 
android:paddingTop="1dip" 
android:paddingRight="1dip" 
android:paddingBottom="1dip"

如果左右上下都是相同的设置则可以直接设置

android:layout_margin="10dip" 
android:padding="5dip"

 

Android支持的长度单位。

  • px(像素):屏幕上的点。 
    pixels(像素). 不同设备显示效果相同,一般我们HVGA代表320x480像素,这个用的比较多。
  • in(英寸):长度单位。
  • mm(毫米):长度单位。
  • pt(磅):1/72英寸。 
    point,是一个标准的长度单位,1pt=1/72英寸,用于印刷业,非常简单易用;
  • dp(与密度无关的像素):一种基于屏幕密度的抽象单位。在每英寸160点的显示器上,1dp = 1px。
  • dip:与dp相同,多用于android/ophone示例中。 
    device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。 
  • sp(与刻度无关的像素):与dp类似,但是可以根据用户的字体大小首选项进行缩放。 
    scaled pixels(放大像素). 主要用于字体显示best for textsize。

为了使用户界面能够在现在和将来的显示器类型上正常显示,建议大家始终使用sp作为文字大小的单位,Android默认的字号也是用的sp。

将dip作为其他元素的单位,比如长度、高度。当然,也可以考虑使用矢量图形,而不是用位图。

 

dp是与密度无关,sp除了与密度无关外,还与scale无关。

如果屏幕密度为160,这时dp和sp和px是一样的。1dp=1sp=1px,但如果使用px作单位,如果屏幕大小不变(假设还是3.2寸),而屏幕密度变成了320。

那么原来TextView的宽度设成160px,在密度为320的3.2寸屏幕里看要比在密度为160的3.2寸屏幕上看短了一半。

但如果设置成160dp或160sp的话。系统会自动将width属性值设置成320px的。

也就是160 * 320 / 160。其中320 / 160可称为密度比例因子。也就是说,如果使用dp和sp,系统会根据屏幕密度的变化自动进行转换.



package com.example.calculator; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { // 记忆功能变量 private TextView tv_mc,tv_mr; private double memoryValue = 0; // UI组件 private TextView displayTextView; private TextView expressionTextView; // 计算器状态变量 private double previousValue = 0; private String pendingOperator = ""; private boolean isNewNumber = true; private boolean resetOnNextInput = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeViews(); setupButtonClickListeners(); } private void initializeViews() { displayTextView = findViewById(R.id.editText); expressionTextView = findViewById(R.id.editText_1); tv_mc=findViewById(R.id.tv_mc); tv_mr=findViewById(R.id.tv_mr); updateDisplay("0"); } private void setupButtonClickListeners() { // 数字按钮 findViewById(R.id.btn_num_0).setOnClickListener(v -> onNumberClick("0")); findViewById(R.id.btn_num_1).setOnClickListener(v -> onNumberClick("1")); findViewById(R.id.btn_num_2).setOnClickListener(v -> onNumberClick("2")); findViewById(R.id.btn_num_3).setOnClickListener(v -> onNumberClick("3")); findViewById(R.id.btn_num_4).setOnClickListener(v -> onNumberClick("4")); findViewById(R.id.btn_num_5).setOnClickListener(v -> onNumberClick("5")); findViewById(R.id.btn_num_6).setOnClickListener(v -> onNumberClick("6")); findViewById(R.id.btn_num_7).setOnClickListener(v -> onNumberClick("7")); findViewById(R.id.btn_num_8).setOnClickListener(v -> onNumberClick("8")); findViewById(R.id.btn_num_9).setOnClickListener(v -> onNumberClick("9")); // 小数点按钮 findViewById(R.id.btn_num_dot).setOnClickListener(v -> onDecimalClick()); // 运算符按钮 findViewById(R.id.btn_symbol_plus).setOnClickListener(v -> onOperatorClick("+")); findViewById(R.id.btn_symbol_minus).setOnClickListener(v -> onOperatorClick("-")); findViewById(R.id.btn_symbol_multiply).setOnClickListener(v -> onOperatorClick("×")); findViewById(R.id.btn_symbol_divide).setOnClickListener(v -> onOperatorClick("÷")); findViewById(R.id.btn_symbol_equals).setOnClickListener(v -> onEqualsClick()); // 功能按钮 findViewById(R.id.btn_clear).setOnClickListener(v -> onClearClick()); findViewById(R.id.btn_clear_entry).setOnClickListener(v -> onClearEntryClick()); findViewById(R.id.btn_clear_image).setOnClickListener(v -> onBackspaceClick()); findViewById(R.id.btn_symbol_plus_minus).setOnClickListener(v -> onPlusMinusClick()); findViewById(R.id.btn_symbol_percent).setOnClickListener(v -> onPercentClick()); // 科学计算按钮 findViewById(R.id.btn_symbol_square_root).setOnClickListener(v -> onSqrtClick()); findViewById(R.id.btn_symbol_square).setOnClickListener(v -> onSquareClick()); findViewById(R.id.btn_symbol_x_inverse).setOnClickListener(v -> onReciprocalClick()); // 记忆功能按钮 findViewById(R.id.tv_mc).setOnClickListener(v -> onMemoryClearClick()); findViewById(R.id.tv_mr).setOnClickListener(v -> onMemoryRecallClick()); findViewById(R.id.tv_m_plus).setOnClickListener(v -> onMemoryAddClick()); findViewById(R.id.tv_m_minus).setOnClickListener(v -> onMemorySubtractClick()); findViewById(R.id.tv_ms).setOnClickListener(v -> onMemoryStoreClick()); } /** * 处理数字按钮点击事件 * * @param number 按下的数字 */ private void onNumberClick(String number) { if (resetOnNextInput) { resetCalculator(); } String currentDisplay = displayTextView.getText().toString(); String digitsOnly = currentDisplay.replace(".", "").replace("-", ""); if (digitsOnly.length() >= 9 && !isNewNumber) { return; } if (isNewNumber) { updateDisplay(number); isNewNumber = false; } else { if (currentDisplay.equals("0")) { updateDisplay(number); } else { updateDisplay(currentDisplay + number); } } } /** * 处理小数点按钮点击事件 */ private void onDecimalClick() { if (resetOnNextInput) { resetCalculator(); } String currentDisplay = displayTextView.getText().toString(); if (isNewNumber) { updateDisplay("0."); isNewNumber = false; } else if (!currentDisplay.contains(".")) { updateDisplay(currentDisplay + "."); } } /** * 处理运算符按钮点击事件 * * @param operator 运算符 (+, -, ×, ÷) */ private void onOperatorClick(String operator) { String currentDisplay = displayTextView.getText().toString(); // 格式化当前显示的数字,去除不必要的小数点零 double currentValue = Double.parseDouble(currentDisplay); String formattedValue = formatResult(currentValue); if (!pendingOperator.isEmpty()) { // 如果已有待处理的运算符,先计算之前的表达式 onEqualsClick(); formattedValue = formatResult(Double.parseDouble(displayTextView.getText().toString())); } else { previousValue = currentValue; } pendingOperator = operator; isNewNumber = true; resetOnNextInput = false; // 更新表达式显示,使用格式化后的数值 expressionTextView.setText(formattedValue + " " + operator); } /** * 处理等号按钮点击事件 */ private void onEqualsClick() { if (pendingOperator.isEmpty()) return; String currentDisplay = displayTextView.getText().toString(); double currentValue = Double.parseDouble(currentDisplay); // 格式化当前显示的数值 String formattedCurrentValue = formatResult(currentValue); double result = 0; try { switch (pendingOperator) { case "+": result = previousValue + currentValue; break; case "-": result = previousValue - currentValue; break; case "×": result = previousValue * currentValue; break; case "÷": if (currentValue == 0) { // 处理除零错误 updateDisplay("除数不能为0"); expressionTextView.setText(""); resetCalculator(); return; } result = previousValue / currentValue; break; } // 格式化结果 String resultStr = formatResult(result); updateDisplay(resultStr); // 更新表达式显示,使用格式化后的数值 String formattedPreviousValue = formatResult(previousValue); expressionTextView.setText(formattedPreviousValue + " " + pendingOperator + " " + formattedCurrentValue + " ="); // 重置状态 previousValue = result; pendingOperator = ""; isNewNumber = true; resetOnNextInput = true; } catch (Exception e) { updateDisplay("错误"); expressionTextView.setText(""); resetCalculator(); } } /** * 处理清除按钮点击事件(清除所有) */ private void onClearClick() { resetCalculator(); updateDisplay("0"); expressionTextView.setText(""); } /** * 处理清除条目按钮点击事件(仅清除当前输入) */ private void onClearEntryClick() { updateDisplay("0"); isNewNumber = true; } /** * 处理退格按钮点击事件 */ private void onBackspaceClick() { String currentDisplay = displayTextView.getText().toString(); if (currentDisplay.equals("错误")) { resetCalculator(); updateDisplay("0"); return; } if (currentDisplay.length() > 1) { updateDisplay(currentDisplay.substring(0, currentDisplay.length() - 1)); } else { updateDisplay("0"); isNewNumber = true; } } /** * 处理正负号切换按钮点击事件 */ private void onPlusMinusClick() { String currentDisplay = displayTextView.getText().toString(); if (currentDisplay.equals("错误")) return; if (currentDisplay.startsWith("-")) { updateDisplay(currentDisplay.substring(1)); } else if (!currentDisplay.equals("0")) { updateDisplay("-" + currentDisplay); } } /** * 处理百分号按钮点击事件 */ private void onPercentClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); double result = value / 100; updateDisplay(formatResult(result)); isNewNumber = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 处理平方根按钮点击事件 */ private void onSqrtClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); if (value < 0) { updateDisplay("无效输入"); resetOnNextInput = true; return; } double result = Math.sqrt(value); updateDisplay(formatResult(result)); expressionTextView.setText("√(" + value + ")"); isNewNumber = true; resetOnNextInput = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 处理平方按钮点击事件 */ private void onSquareClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); double result = value * value; updateDisplay(formatResult(result)); expressionTextView.setText("sqr(" + value + ")"); isNewNumber = true; resetOnNextInput = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 处理倒数按钮点击事件 */ private void onReciprocalClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); if (value == 0) { updateDisplay("不能除以零"); resetOnNextInput = true; return; } double result = 1 / value; updateDisplay(formatResult(result)); expressionTextView.setText("1/(" + value + ")"); isNewNumber = true; resetOnNextInput = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 格式化计算结果 * * @param result 计算结果 * @return 格式化后的字符串 */ private String formatResult(double result) { // 如果是整数,不显示小数点 if (result == (long) result) { return String.valueOf((long) result); } else { // 处理浮点数精度问题,保留合适的位数 String resultStr = String.format("%.10f", result); // 移除末尾的0 resultStr = resultStr.replaceAll("0*$", "").replaceAll("\\.$", ""); return resultStr; } } /** * 更新显示屏显示内容 * @param value 要显示的值 */ /** * 更新显示屏显示内容 * * @param value 要显示的值 */ private void updateDisplay(String value) { // 处理显示长度限制 String digitsOnly = value.replace(".", "").replace("-", ""); if (digitsOnly.length() >= 10) { value = value.substring(0, 10); } displayTextView.setText(value); } /** * 重置计算器状态 */ private void resetCalculator() { previousValue = 0; pendingOperator = ""; isNewNumber = true; resetOnNextInput = false; } /** * 处理记忆清除按钮点击事件 (MC) */ private void onMemoryClearClick() { memoryValue = 0; tv_mr.setTextColor(Color.parseColor("#808080")); tv_mc.setTextColor(Color.parseColor("#808080")); } /** * 处理记忆调用按钮点击事件 (MR) */ private void onMemoryRecallClick() { updateDisplay(formatResult(memoryValue)); isNewNumber = true; tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } /** * 处理记忆加法按钮点击事件 (M+) */ private void onMemoryAddClick() { try { double currentValue = Double.parseDouble(displayTextView.getText().toString()); memoryValue += currentValue; tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } catch (NumberFormatException e) { // 忽略无效数字 } } /** * 处理记忆减法按钮点击事件 (M-) */ private void onMemorySubtractClick() { try { double currentValue = Double.parseDouble(displayTextView.getText().toString()); memoryValue -= currentValue; tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } catch (NumberFormatException e) { // 忽略无效数字 } } /** * 处理记忆存储按钮点击事件 (MS) */ private void onMemoryStoreClick() { try { memoryValue = Double.parseDouble(displayTextView.getText().toString()); tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } catch (NumberFormatException e) { updateDisplay("错误"); } } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ECECEC" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.4" android:orientation="horizontal"> <ImageView android:padding="2dp" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/img_jisuanqi"/> <TextView android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:text="计算器" android:textColor="#000000" android:textSize="15sp" android:layout_marginLeft="8dp" android:gravity="center_vertical"/> <ImageView android:layout_width="60dp" android:layout_height="30dp" android:src="@drawable/img_jianhao" android:padding="6dp"/> <ImageView android:layout_width="60dp" android:layout_height="30dp" android:padding="6dp" android:src="@drawable/img_square"/> <ImageView android:layout_width="60dp" android:layout_height="30dp" android:padding="6dp" android:src="@drawable/img_cha"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.6" android:orientation="horizontal" android:layout_marginTop="10dp" android:gravity="center"> <ImageView android:padding="6dp" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/img_gang"/> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="标准" android:textColor="#000000" android:textSize="30sp" android:textStyle="bold" android:layout_marginLeft="8dp" android:gravity="center_vertical"/> <ImageView android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:scaleType="fitStart" android:src="@drawable/img_top"/> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:padding="6dp" android:src="@drawable/img_lishi"/> </LinearLayout> <HorizontalScrollView android:id="@+id/scrollView_1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.5" android:scrollbars="none" android:background="@drawable/biankuang"> <EditText android:textColor="#808080" android:id="@+id/editText_1" android:layout_width="wrap_content" android:layout_height="match_parent" android:textSize="30sp" android:focusable="false" android:focusableInTouchMode="false" android:clickable="true" android:cursorVisible="false" android:background="@null" android:maxLines="1" android:scrollHorizontally="true" android:inputType="none" android:layout_gravity="right|center"/> </HorizontalScrollView> <HorizontalScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/biankuang" android:scrollbars="none"> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right|center" android:background="@null" android:clickable="true" android:cursorVisible="false" android:focusable="false" android:focusableInTouchMode="false" android:inputType="none" android:maxLines="1" android:scrollHorizontally="true" android:text="0" android:textSize="60sp" /> </HorizontalScrollView> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.5" android:orientation="horizontal"> <TextView android:id="@+id/tv_mc" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="MC" android:textSize="15dp" android:textColor="#808080"/> <TextView android:id="@+id/tv_mr" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="MR" android:textSize="15dp" android:textColor="#808080"/> <TextView android:id="@+id/tv_m_plus" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="M+" android:textColor="@color/black" android:textSize="15dp" /> <TextView android:id="@+id/tv_m_minus" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="M-" android:textColor="@color/black" android:textSize="15dp" /> <TextView android:id="@+id/tv_ms" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="MS" android:textColor="@color/black" android:textSize="15dp" /> <TextView android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="M⋁" android:textSize="15dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="7" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_symbol_percent" android:layout_gravity="center" android:text="%" android:textSize="20sp" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background" /> <Button android:id="@+id/btn_clear_entry" android:layout_gravity="center" android:text="CE" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> <Button android:id="@+id/btn_clear" android:layout_gravity="center" android:text="C" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> <ImageView android:id="@+id/btn_clear_image" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:padding="10dp" android:background="@drawable/rounded_button_background" android:scaleType="fitCenter" android:src="@drawable/img_qingchu" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_symbol_x_inverse" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background" android:text="1/x" android:textColor="@color/black" android:textSize="20sp"/> <Button android:id="@+id/btn_symbol_square" android:layout_gravity="center" android:text="x²" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background" /> <ImageView android:id="@+id/btn_symbol_square_root" android:layout_gravity="center" android:src="@drawable/img_sqrt" android:padding="18dp" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/>\ <Button android:id="@+id/btn_symbol_divide" android:layout_gravity="center" android:text="÷" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_num_7" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="7" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_8" android:layout_width="0dp" android:layout_height="55dp" android:layout_gravity="center" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="8" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_9" android:layout_gravity="center" android:text="9" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background"/>\ <Button android:id="@+id/btn_symbol_multiply" android:layout_gravity="center" android:text="×" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_num_4" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="4" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_5" android:layout_gravity="center" android:text="5" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" /> <Button android:id="@+id/btn_num_6" android:layout_width="0dp" android:layout_height="55dp" android:layout_gravity="center" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="6" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_symbol_minus" android:layout_gravity="center" android:text="-" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_num_1" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="1" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_2" android:layout_gravity="center" android:text="2" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" /> <Button android:id="@+id/btn_num_3" android:layout_gravity="center" android:text="3" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background"/>\ <Button android:id="@+id/btn_symbol_plus" android:layout_gravity="center" android:text="+" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_symbol_plus_minus" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="+/-" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_0" android:layout_gravity="center" android:text="0" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" /> <Button android:id="@+id/btn_num_dot" android:layout_gravity="center" android:text="." android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background"/>\ <Button android:id="@+id/btn_symbol_equals" android:layout_width="0dp" android:layout_height="55dp" android:layout_gravity="center" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/equals" android:text="=" android:textColor="@color/black" android:textSize="20sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.2"> </LinearLayout> </LinearLayout> </LinearLayout>解析每个步骤并详细解释对应的功能
最新发布
10-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值