Make a simple calculator interface with Android Studio

For the calculator interface, I was writing in the xml file

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/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"
                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:height="140px"
                android:text="9"
                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_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"
                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="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"
            android:height="140px"
            android:text="="
            android:textSize="50px"/>
    </TableRow>
    </TableLayout>

</TableLayout>

Here is the problem I encountered when writing:

1.Tablelayout how to make four buttons in a row filled his party?

 

<TableLayout
        android:stretchColumns="0,1,2,3">

A column control button fill the remaining space stretching, 0 is the first column.

2. How to make the last line of the first button accounted for two?

 

<Button
            android:layout_span="2"

 

Directly in the button tag accounted for two.

3. How to make Textview in the text right?

<TextView
                android:gravity="right"

 

Guess you like

Origin www.cnblogs.com/slender-elf/p/12507953.html