安卓控件
2023年10月30日空间生命周期
Ø onCreate:创建活动。把页面布局加载进内存,进入了初始状态。
Ø onStart:开始活动。把活动页面显示在屏幕上,进入了就绪状态。
Ø onResume:恢复活动。活动页面进入活跃状态,能够与用户正常交互,例如允许响应用户的点击动作、允许用户输入文字等等。
Ø onPause:暂停活动。页面进入暂停状态,无法与用户正常交互。
Ø onStop:停止活动。页面将不在屏幕上显示。
Ø onDestroy:销毁活动。回收活动占用的系统资源,把页面从内存中清除。
Ø onRestart:重启活动。重新加载内存中的页面数据。
Ø onNewIntent:重用已有的活动实例。
添加事件开始
xml 代码
1 2 3 4 5 6 7 8 |
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="直接指定点击方法" android:textAllCaps="false" android:textColor="@color/black" android:textSize="17sp" android:onClick="doClick"/> |
java 代码
1 2 3 4 |
public void doClick(View view) { String desc = String.format("%s 您点击了按钮: %s", DateUtil.getNowTime(), ((Button) view).getText()); tv_result.setText(desc); } |
线性布局开始
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<?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"> <!--线性布局水平方向开始--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="横排第一个" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="横排第二个" android:textColor="#000000" android:textSize="17sp" /> </LinearLayout> <!--线性布局水平方向结束--> <!--线性布局垂直方向开始--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:text="竖排第一个" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:text="竖排第二个" android:textColor="#000000" android:textSize="17sp" /> </LinearLayout> <!--线性布局垂直方向结束--> </LinearLayout> |
相对布局开始
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
<?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"> <!--相对布局开始--> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="200dp"> <!--水平垂直居中开始--> <TextView android:id="@+id/tv_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#ffffff" android:text="我在中间" android:textColor="#000000" android:textSize="11sp" /> <!--水平垂直居中结束--> <!--水平居中开始--> <TextView android:id="@+id/tv_center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="#ffffff" android:text="我在水平中间" android:textColor="#000000" android:textSize="11sp" /> <!--水平居中结束--> <!--垂直居中开始--> <TextView android:id="@+id/tv_center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:background="#ffffff" android:text="我在垂直中间" android:textColor="#000000" android:textSize="11sp" /> <!--垂直居中结束--> <!--跟上级顶部对齐开始--> <TextView android:id="@+id/tv_parent_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:background="#ffffff" android:text="我跟上级顶部对齐" android:textColor="#000000" android:textSize="11sp" /> <!--跟上级顶部对齐结束--> <!--跟上级底部对齐开始--> <TextView android:id="@+id/tv_parent_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#ffffff" android:text="我跟上级底部对齐" android:textColor="#000000" android:textSize="11sp" /> <!--跟上级底部对齐结束--> <!--围绕着某个元素布局开始--> <TextView android:id="@+id/tv_left_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/tv_center" android:layout_toLeftOf="@id/tv_center" android:background="#ffffff" android:text="我在中间左边" android:textColor="#000000" android:textSize="11sp" /> <TextView android:id="@+id/tv_right_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/tv_center" android:layout_toRightOf="@id/tv_center" android:background="#ffffff" android:text="我在中间右边" android:textColor="#000000" android:textSize="11sp" /> <TextView android:id="@+id/tv_above_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/tv_center" android:layout_alignLeft="@id/tv_center" android:background="#ffffff" android:text="我在中间上面" android:textColor="#000000" android:textSize="11sp" /> <TextView android:id="@+id/tv_below_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv_center" android:layout_alignRight="@id/tv_center" android:background="#ffffff" android:text="我在中间下面" android:textColor="#000000" android:textSize="11sp" /> <!--围绕着某个元素布局结束--> </RelativeLayout> <!--相对布局结束--> <!--相对布局开始--> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="200dp"> <!--顶部左侧开始--> <TextView android:id="@+id/tv_parent_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:background="#ffffff" android:text="我跟上级左边对齐" android:textColor="#000000" android:textSize="11sp" /> <!--顶部左侧结束--> <!--顶部右侧开始--> <TextView android:id="@+id/tv_parent_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:background="#ffffff" android:text="我跟上级右边对齐" android:textColor="#000000" android:textSize="11sp" /> <!--顶部右侧结束--> </RelativeLayout> <!--相对布局结束--> </LinearLayout> |
栅格布局开始
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:columnCount="2" android:rowCount="2"> <TextView android:layout_width="0dp" android:layout_height="60dp" android:layout_columnWeight="1" android:background="#ffcccc" android:gravity="center" android:text="浅红色" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="0dp" android:layout_height="60dp" android:layout_columnWeight="1" android:background="#ffaa00" android:gravity="center" android:text="橙色" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="0dp" android:layout_height="60dp" android:layout_columnWeight="1" android:background="#00ff00" android:gravity="center" android:text="绿色" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="0dp" android:layout_height="60dp" android:layout_columnWeight="1" android:background="#660066" android:gravity="center" android:text="深紫色" android:textColor="#000000" android:textSize="17sp" /> </GridLayout> |
滚动视图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?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"> <HorizontalScrollView android:layout_width="wrap_content" android:layout_height="200dp"> <!--水平滚动开始--> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal"> <View android:layout_width="300dp" android:layout_height="match_parent" android:background="#aaffff"/> <View android:layout_width="300dp" android:layout_height="match_parent" android:background="#ffff00"/> </LinearLayout> <!--水平滚动结束--> </HorizontalScrollView> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- 垂直滚动开始 --> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="400dp" android:background="#00ff00"/> <View android:layout_width="match_parent" android:layout_height="400dp" android:background="#ffffaa"/> </LinearLayout> <!--垂直滚动结束--> </ScrollView> </LinearLayout> |
指定视图大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?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"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:background="#00ffff" android:text="视图宽度采用wrap_content定义" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:background="#00ffff" android:text="视图宽度采用match_parent定义" android:textColor="#000000" android:textSize="17sp" /> <TextView android:layout_width="300dp" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:background="#00ffff" android:text="视图宽度采用固定大小" android:textColor="#000000" android:textSize="17sp" /> <TextView android:id="@+id/tv_code" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:background="#00ffff" android:text="通过代码指定视图宽度" android:textColor="#000000" android:textSize="17sp" /> </LinearLayout> |
gravity 和layout_gravity 对齐位置,和float差不多
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?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="300dp" android:background="#ffff99" android:orientation="horizontal"> <!-- 第一个子布局背景为红色,它在上级视图中朝下对齐,它的下级视图则靠左对齐 --> <LinearLayout android:layout_width="0dp" android:layout_height="200dp" android:layout_gravity="bottom" android:layout_margin="10dp" android:layout_weight="1" android:background="#ff0000" android:padding="10dp" android:gravity="left"> <!-- 内部视图的宽度和高度都是100dp,且背景色为青色 --> <View android:layout_width="100dp" android:layout_height="100dp" android:background="#00ffff"/> </LinearLayout> <!-- 第二个子布局背景为红色,它在上级视图中朝上对齐,它的下级视图则靠右对齐 --> <LinearLayout android:layout_width="0dp" android:layout_height="200dp" android:layout_gravity="top" android:layout_margin="10dp" android:layout_weight="1" android:background="#ff0000" android:padding="10dp" android:gravity="right"> <View android:layout_width="100dp" android:layout_height="100dp" android:background="#00ffff"/> </LinearLayout> </LinearLayout> |
视图margin外边距
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?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="300dp" android:background="#00AAFF" android:orientation="vertical"> <!-- 中间层的布局背景为黄色 --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="20dp" android:background="#FFFF99" android:padding="60dp"> <!-- 最内层的视图背景为红色 --> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF0000"/> </LinearLayout> </LinearLayout> |
图片在左边的按钮
在目录下添加图片 /app/src/main/res/drawable/ic_about.png
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?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"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="图标在左" android:drawableLeft="@drawable/ic_about" android:background="#FFFFFF" android:drawablePadding="5dp"/> </LinearLayout> |
展示图片
在目录下添加图片/src/main/res/drawable/apple.png
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?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"> <ImageView android:id="@+id/iv_scale" android:layout_width="match_parent" android:layout_height="220dp" android:layout_marginTop="5dp" android:src="@drawable/apple" android:scaleType="centerInside"/> <!--android:src="@drawable/apple" --> </LinearLayout> |
计算器开始
逻辑层
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private TextView tv_result; // 第一个操作数 private String firstNum = ""; // 运算符 private String operator = ""; // 第二个操作数 private String secondNum = ""; // 当前的计算结果 private String result = ""; // 显示的文本内容 private String showText = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 从布局文件中获取名叫tv_result的文本视图 tv_result = findViewById(R.id.tv_result); // 下面给每个按钮控件都注册了点击监听器 findViewById(R.id.btn_cancel).setOnClickListener(this); findViewById(R.id.btn_divide).setOnClickListener(this); // “除法”按钮 findViewById(R.id.btn_multiply).setOnClickListener(this); // “乘法”按钮 findViewById(R.id.btn_clear).setOnClickListener(this); // “清除”按钮 findViewById(R.id.btn_seven).setOnClickListener(this); // 数字7 findViewById(R.id.btn_eight).setOnClickListener(this); // 数字8 findViewById(R.id.btn_nine).setOnClickListener(this); // 数字9 findViewById(R.id.btn_plus).setOnClickListener(this); // “加法”按钮 findViewById(R.id.btn_four).setOnClickListener(this); // 数字4 findViewById(R.id.btn_five).setOnClickListener(this); // 数字5 findViewById(R.id.btn_six).setOnClickListener(this); // 数字6 findViewById(R.id.btn_minus).setOnClickListener(this); // “减法”按钮 findViewById(R.id.btn_one).setOnClickListener(this); // 数字1 findViewById(R.id.btn_two).setOnClickListener(this); // 数字2 findViewById(R.id.btn_three).setOnClickListener(this); // 数字3 findViewById(R.id.btn_reciprocal).setOnClickListener(this); // 求倒数按钮 findViewById(R.id.btn_zero).setOnClickListener(this); // 数字0 findViewById(R.id.btn_dot).setOnClickListener(this); // “小数点”按钮 findViewById(R.id.btn_equal).setOnClickListener(this); // “等号”按钮 findViewById(R.id.ib_sqrt).setOnClickListener(this); // “开平方”按钮 } @Override public void onClick(View v) { String inputText; // 如果是开根号按钮 if (v.getId() == R.id.ib_sqrt) { inputText = "√"; } else { // 除了开根号之外的其他按钮 inputText = ((TextView) v).getText().toString(); } switch (v.getId()) { // 点击了清除按钮 case R.id.btn_clear: clear(); break; // 点击了取消按钮 case R.id.btn_cancel: break; // 点击了加、减、乘、除按钮 case R.id.btn_plus: case R.id.btn_minus: case R.id.btn_multiply: case R.id.btn_divide: operator = inputText; // 运算符 refreshText(showText + operator); break; // 点击了等号按钮 case R.id.btn_equal: // 加减乘除四则运算 double calculate_result = calculateFour(); refreshOperate(String.valueOf(calculate_result)); refreshText(showText + "=" + result); break; // 点击了开根号按钮 case R.id.ib_sqrt: double sqrt_result = Math.sqrt(Double.parseDouble(firstNum)); refreshOperate(String.valueOf(sqrt_result)); refreshText(showText + "√=" + result); break; // 点击了求倒数按钮 case R.id.btn_reciprocal: double reciprocal_result = 1.0 / Double.parseDouble(firstNum); refreshOperate(String.valueOf(reciprocal_result)); refreshText(showText + "/=" + result); break; // 点击了其他按钮,包括数字和小数点 default: // 上次的运算结果已经出来了 if (result.length() > 0 && operator.equals("")) { clear(); } // 无运算符,则继续拼接第一个操作数 if (operator.equals("")) { firstNum = firstNum + inputText; } else { // 有运算符,则继续拼接第二个操作数 secondNum = secondNum + inputText; } // 整数不需要前面的0 if (showText.equals("0") && !inputText.equals(".")) { refreshText(inputText); } else { refreshText(showText + inputText); } break; } } // 加减乘除四则运算,返回计算结果 private double calculateFour() { switch (operator) { case "+": return Double.parseDouble(firstNum) + Double.parseDouble(secondNum); case "-": return Double.parseDouble(firstNum) - Double.parseDouble(secondNum); case "×": return Double.parseDouble(firstNum) * Double.parseDouble(secondNum); default: return Double.parseDouble(firstNum) / Double.parseDouble(secondNum); } } // 清空并初始化 private void clear() { refreshOperate(""); refreshText(""); } // 刷新运算结果 private void refreshOperate(String new_result) { result = new_result; firstNum = result; secondNum = ""; operator = ""; } // 刷新文本显示 private void refreshText(String text) { showText = text; tv_result.setText(showText); } } |
视图层
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
<?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:background="#EEEEEE" android:orientation="vertical" android:padding="5dp"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/simple_calculator" android:textColor="@color/black" android:textSize="20sp" /> <TextView android:id="@+id/tv_result" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:gravity="right|bottom" android:lines="3" android:text="0" android:textColor="@color/black" android:textSize="25sp" /> <GridLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:columnCount="4" android:rowCount="5"> <Button android:id="@+id/btn_cancel" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/cancel" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_divide" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/divide" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_multiply" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/multiply" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_clear" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/clear" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_seven" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/seven" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_eight" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/eight" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_nine" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/nine" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_plus" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/plus" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_four" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/four" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_five" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/five" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_six" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/six" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_minus" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/minus" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_one" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/one" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_two" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/two" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_three" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/three" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <ImageButton android:id="@+id/ib_sqrt" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:scaleType="centerInside" android:src="@drawable/sqrt" /> <Button android:id="@+id/btn_reciprocal" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/reciprocal" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_zero" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/zero" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_dot" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/dot" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> <Button android:id="@+id/btn_equal" android:layout_width="0dp" android:layout_height="@dimen/button_height" android:layout_columnWeight="1" android:gravity="center" android:text="@string/equal" android:textColor="@color/black" android:textSize="@dimen/button_font_size" /> </GridLayout> </LinearLayout> </ScrollView> </LinearLayout> |