ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 안드로이드 숙제
    program_language 및 궁금한것/Android Studio 2018. 4. 10. 09:00

    메인

    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
    package com.example.administrator.homework;
     
    import android.annotation.SuppressLint;
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.text.Layout;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;
    import android.widget.TextView;
     
    public class MainActivity extends AppCompatActivity implements OnClickListener {
        TextView txt1;
        TextView txt2;
        TextView txt3;
        RelativeLayout layout1, layout2, layout3;
        EditText edit1;
        EditText edit2;
        EditText edit3;
     
        @SuppressLint("WrongViewCast")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            txt1 = (TextView) findViewById(R.id.txt1);
            txt2 = (TextView) findViewById(R.id.txt2);
            txt3 = (TextView) findViewById(R.id.txt3);
     
            edit1 = (EditText) findViewById(R.id.edit1);
            edit2 = (EditText) findViewById(R.id.edit2);
            edit3 = (EditText) findViewById(R.id.edit3);
     
            Button button1 = (Button) findViewById(R.id.button1);
            button1.setOnClickListener(this);
            Button button2 = (Button) findViewById(R.id.button2);
            button2.setOnClickListener(this);
            Button button3 = (Button) findViewById(R.id.button3);
            button3.setOnClickListener(this);
            Button resultbt = (Button) findViewById(R.id.resultbt);
            button3.setOnClickListener(this);
     
            layout1 = (RelativeLayout) findViewById(R.id.layout1);
            layout2 = (RelativeLayout) findViewById(R.id.layout2);
            layout3 = (RelativeLayout) findViewById(R.id.layout3);
        }
     
        @Override
        public void onClick(View v) {
    //        red.setVisibility(View.INVISIBLE);
    //        green.setVisibility(View.VISIBLE);
            String a = edit1.getText().toString();
            String b = edit2.getText().toString();
            int result;
     
            txt1.setText("뭐가 나올까?");
     
            if (v.getId() == R.id.button1) {
                layout1.setVisibility(View.VISIBLE);
                layout2.setVisibility(View.INVISIBLE);
                layout3.setVisibility(View.INVISIBLE);
     
                txt1.setText("구구단");
                if (v.getId() == R.id.resultbt||edit2.equals("+")) {
                    a = edit1.getText().toString();
                    b = edit3.getText().toString();
                    result = Integer.parseInt(a) * Integer.parseInt(b);
                    txt1.setText(result);
                    }
     
                } else if (v.getId() == R.id.button2) {
                    layout1.setVisibility(View.INVISIBLE);
                    layout2.setVisibility(View.VISIBLE);
                    layout3.setVisibility(View.INVISIBLE);
     
                    txt2.setText("6월달력");
     
     
                } else if (v.getId() == R.id.button3) {
                    layout1.setVisibility(View.INVISIBLE);
                    layout2.setVisibility(View.INVISIBLE);
                    layout3.setVisibility(View.VISIBLE);
     
                    txt3.setText("로또");
     
                }
     
            }
        }
     
     
     
    cs


     
        

    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
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
        android:layout_margin="10dp"
        tools:context=".MainActivity">
     
        <Button
            android:id="@+id/button1"
            android:layout_width="70dp"
            android:layout_height="50dp"
            android:background="#0000ff"
            android:text="Button"
            android:textColor="#FFFF00"
            />
     
        <Button
            android:id="@+id/button2"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_marginHorizontal="20dp"
            android:layout_toRightOf="@id/button1"
            android:background="#00FA9A"
            android:text="Button"
            android:textColor="#FFFF00" />
     
        <Button
            android:id="@+id/button3"
            android:layout_width="110dp"
            android:layout_height="50dp"
            android:layout_toRightOf="@id/button2"
            android:background="#800080"
            android:text="Button"
            android:textColor="#FFFF00" />
     
        <RelativeLayout
            android:id="@+id/layout1"
            android:visibility="visible"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/button1"
            android:background="#FFDEAD">
     
            <EditText
                android:id="@+id/edit1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="숫자"
                android:textSize="50dp"
                android:layout_toLeftOf="@+id/edit2"
                />
     
            <EditText
                android:id="@+id/edit2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="기호"
                android:textSize="50dp"
                android:layout_centerHorizontal="true"/>
     
            <EditText
                android:id="@+id/edit3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/edit2"
                android:textSize="50dp"
                android:hint="숫자"/>
     
     
            <TextView
                android:id="@+id/txt1"
                android:layout_width="330dp"
                android:layout_height="50dp"
                android:textColor="#ffffff"
                android:layout_alignParentBottom="true"
                android:text="계산할 숫자를 입력하세요."
                android:textSize="30dp"
                />
     
        </RelativeLayout>
     
        <RelativeLayout
            android:id="@+id/layout2"
            android:visibility="invisible"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/button1"
            android:background="#00FA9A">
     
            <TextView
                android:id="@+id/txt2"
                android:layout_width="150dp"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:text="TextView"
                android:textSize="30dp" />
     
        </RelativeLayout>
     
        <RelativeLayout
            android:id="@+id/layout3"
            android:visibility="invisible"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/button1"
            android:background="#800080">
     
            <TextView
                android:id="@+id/txt3"
                android:layout_width="150dp"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:text="TextView"
                android:textSize="30dp" />
     
        </RelativeLayout>
    </RelativeLayout>
     
    cs

    마진은 나와 부모의 사이를 나타내는것

    패딩은 나와 자식사이를 나타내는것이다.


    숙제는 상단에 세개의 버튼을 놓고 하나 클릭시 다른 화면을 출력하세요.

    첫번째는 달력 구구단 등을 출력해 주세요.

    반응형

    'program_language 및 궁금한것 > Android Studio' 카테고리의 다른 글

    LineaLayout  (0) 2018.04.13
    setVisibility //// visible, invisible  (0) 2018.04.12
    안드로이드 방탈출!! 거의완성..  (0) 2018.04.05
    이전수업에 했던것  (0) 2018.04.05
    버튼에 설정넣기.  (0) 2018.04.05

    댓글

Designed by Tistory.