-
안드로이드 숙제program_language 및 궁금한것/Android Studio 2018. 4. 10. 09:00
메인
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697package 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")@Overrideprotected 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);}@Overridepublic 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 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121<?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"><Buttonandroid:id="@+id/button1"android:layout_width="70dp"android:layout_height="50dp"android:background="#0000ff"android:text="Button"android:textColor="#FFFF00"/><Buttonandroid: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" /><Buttonandroid: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" /><RelativeLayoutandroid:id="@+id/layout1"android:visibility="visible"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/button1"android:background="#FFDEAD"><EditTextandroid:id="@+id/edit1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="숫자"android:textSize="50dp"android:layout_toLeftOf="@+id/edit2"/><EditTextandroid:id="@+id/edit2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="기호"android:textSize="50dp"android:layout_centerHorizontal="true"/><EditTextandroid:id="@+id/edit3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@+id/edit2"android:textSize="50dp"android:hint="숫자"/><TextViewandroid:id="@+id/txt1"android:layout_width="330dp"android:layout_height="50dp"android:textColor="#ffffff"android:layout_alignParentBottom="true"android:text="계산할 숫자를 입력하세요."android:textSize="30dp"/></RelativeLayout><RelativeLayoutandroid:id="@+id/layout2"android:visibility="invisible"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/button1"android:background="#00FA9A"><TextViewandroid:id="@+id/txt2"android:layout_width="150dp"android:layout_height="50dp"android:layout_alignParentBottom="true"android:text="TextView"android:textSize="30dp" /></RelativeLayout><RelativeLayoutandroid:id="@+id/layout3"android:visibility="invisible"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/button1"android:background="#800080"><TextViewandroid: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