728x90
# 실행 화면
# activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/smile"
android:drawableRight="@drawable/smile"
android:text=" 회전하기 "
tools:layout_editor_absoluteX="120dp"
tools:layout_editor_absoluteY="219dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:srcCompat="@drawable/dog" />
</LinearLayout>
# MainActivity.java
package kr.ac.skuniv.rotationtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button button;
ImageView imageView;
int rot = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("2018305065 전유정");
button = (Button) findViewById(R.id.button);
imageView = (ImageView) findViewById(R.id.imageView);
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
rot += 10;
imageView.setRotation(rot);
}
});
}
}
반응형
'전공 공부 > 안드로이드프로그래밍' 카테고리의 다른 글
2개 액티비티 (그림 선택하면 액티비티에 확대되어 정보 출력) (0) | 2021.01.07 |
---|---|
RadioButton, EditText (계산기) (0) | 2021.01.07 |
Toast 메시지 (0) | 2021.01.07 |
LinearLayout (버튼 배열) (0) | 2021.01.07 |
TextView 작성 (0) | 2021.01.07 |