⽤AndroidStudio做⼀个简易的计算器界⾯对于计算器的界⾯,我是在xml⽂件⾥编写
<TableLayout xmlns:android="schemas.android/apk/res/android"
xmlns:app="schemas.android/apk/res-auto"
xmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyCale"
>
<TextView
android:gravity="right"
android:id="@+id/input1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
用java编写一个简单的计算器android:height="100px"
android:text="3+4"
android:textSize="50px"/>
<TextView
android:id="@+id/input2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="200px"
android:text="7"
android:textSize="100px"/>
<TableLayout
android:stretchColumns="0,1,2,3">
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="140px"
android:text="AC"
android:textSize="50px"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:height="140px"
android:text="DEL"
android:textSize="50px"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:height="140px"
android:text="+/-"
android:textSize="50px"/>
<Button
android:layout_width="72dp"
android:layout_height="match_parent"
android:height="140px"
android:text="÷"
android:textSize="50px"/>
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="140px"
android:text="7"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="140px"
android:text="8"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="×"
android:textSize="50px"/>
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="4"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="5"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="6"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                androi
d:height="140px"
android:text="-"
android:textSize="50px"/>
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="1"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="2"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="3"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:height="140px"
android:text="+"
android:textSize="50px"/>
</TableRow>
<TableRow>
<Button
android:layout_span="2"
android:layout_width="match_parent"
android:layout_height="match_parent"            android:height="140px"
android:text="0"
android:textSize="50px"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"            android:height="140px"
android:text="."
android:textSize="50px"/>
<Button
android:layout_height="wrap_content"            android:layout_width="wrap_content"
</TableLayout>
</TableLayout>
下⾯是我在编写时遇到的问题:
1.Tablelayout⾥如何使⼀⾏的四个按钮占满⼀⾏?<TableLayout
android:stretchColumns="0,1,2,3">
控制某列的按钮拉伸占满剩下的空间,0是第⼀列。
2.如何使最后⼀⾏第⼀个按钮占两列?
<Button
android:layout_span="2"
直接在按钮标签⾥设置占两列。
3.如何使Textview⾥的⽂本靠右?
<TextView
android:gravity="right"