安卓课堂练习


1.计算器

示例

    
<?xml version="1.0" encoding="utf-8"?>

    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"
    android:orientation="vertical"
    tools:context=".MainActivity">
    

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:background="#EDEEEE">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="30dp"
            android:layout_marginBottom="60dp"
            android:gravity="right|bottom"
            android:text="0"
            android:textColor="#313131"
            android:textSize="60dp" />

    

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#797979" />
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FDFDFD"
            android:text="C"
            android:textColor="#FF5722"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="DEL"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="÷"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="×"
            android:textSize="25dp" />

    
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#797979" />

    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="7"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="8"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="9"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="-"
            android:textSize="25dp" />

    

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#797979" />

    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="4"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="5"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="6"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="+"
            android:textSize="25dp" />

    

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#797979" />

    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="1"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="2"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="3"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FF5722"
            android:text=""
            android:textSize="25dp" />

    

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="1dp"
            android:layout_weight="3"
            android:background="#797979" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="1dp"
            android:layout_weight="1"
            android:background="#FF5722" />

    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="%"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="0"
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:text="."
            android:textSize="25dp" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#797979" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FF5722"
            android:text="="
            android:textColor="#FFFFFF"
            android:textSize="25dp" />

    

2.梅花布局

<?xml version="1.0" encoding="utf-8"?>