글 번호: 132 작성자: gihun 작성시간: 2023-10-17 22:04:32.833 조회수: 205

오늘자 안드로이드 실습


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:id="@+id/baseLayout"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:gravity="center">

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

        <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="각도 입력"
                android:textSize="20dp"/>

        <EditText
                android:id="@+id/editAngle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="0"/>

    </LinearLayout>
    <!-- For centering ImageView in the middle -->
    <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/jeju2"/>

    <!-- For centering ImageView in the middle -->
    <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"/>


</LinearLayout>

package com.example.myapp2;

import android.annotation.SuppressLint;
import android.view.*;
import android.widget.*;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import static com.example.myapp2.R.id.*;


public class MainActivity extends AppCompatActivity {
    LinearLayout baseLayout;
    EditText edit;
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle("토스트 연습");
        baseLayout = (LinearLayout) findViewById(R.id.baseLayout);
        edit = (EditText) findViewById(R.id.editAngle);
        imageView = (ImageView) findViewById(R.id.imageView1);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu1, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();
        if (itemId == R.id.itemRotate) {
            imageView.setRotation(Float.parseFloat((edit.getText().toString())));
            return true;
        } else if (itemId == R.id.hanra) {
            imageView.setImageResource(R.drawable.jeju2);
            return true;
        } else if (itemId == R.id.chuja) {
            imageView.setImageResource(R.drawable.jeju14);
            return true;
        } else if (itemId == R.id.bumsum) {
            imageView.setImageResource(R.drawable.jeju7);
            return true;
        }
        return false;
    }


}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
            android:id="@+id/itemRotate"
            android:title="그림회전">
    </item>
    <item android:title="그림 변경 >> ">
        <menu>
            <item
                android:id="@+id/hanra"
                android:title="한라산"/>
            />
            <item
                android:id="@+id/chuja"
                android:title="추자도"/>
            <item
                android:id="@+id/bumsum"
                android:title="범섬"/>
            />
        </menu>
    </item>
</menu>


댓글 리스트

Created by 송바래

✉ gihun3645@naver.com

🚩경기도, 성남시