파일명 : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/jeju1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="각도입력" />
<EditText
android:id="@+id/edtAngle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textView1"
android:text="0" />
</RelativeLayout>
파일명 : menu1.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/itemRotate"
android:title="그림회전" />
<group
android:checkableBehavior="single">
<item
android:id="@+id/item1"
android:title="한라산">
</item>
<item
android:id="@+id/item2"
android:title="추자도">
</item>
<item
android:id="@+id/item3"
android:title="범섬">
</item>
</group>
</menu>
파일명 : MainActivity.java
package com.example.it.myapplication7_4;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
EditText edtText;
ImageView imageView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtText = (EditText) findViewById(R.id.edtAngle);
imageView1 = (ImageView) findViewById(R.id.imageView1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater in = getMenuInflater();
in.inflate(R.menu.menu1, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.itemRotate:
imageView1.setRotation(Float.parseFloat(edtText.getText().toString()));
return true;
case R.id.item1:
imageView1.setImageResource(R.drawable.jeju2);
return true;
case R.id.item2:
imageView1.setImageResource(R.drawable.jeju3);
return true;
case R.id.item3:
imageView1.setImageResource(R.drawable.jeju4);
return true;
}
return super.onOptionsItemSelected(item);
}
}
'IT > Android' 카테고리의 다른 글
android - AlertDialog 기본화면 (0) | 2018.09.21 |
---|---|
android - Toast 위치 랜덤으로 표출하기 (0) | 2018.09.21 |
android - context 메뉴 추가 (0) | 2018.09.20 |
android - menu 추가하는 두가지 방법. (xml파일로 추가하기, 자바코드로 추가하기) (0) | 2018.09.20 |
android - 안드로이드 웹뷰(WebView) (0) | 2018.09.19 |