-
직접 풀어보기 5-2Android Studio를 활용한 안드로이드프로그래밍 9판 2024. 5. 3. 04:33
결과창
메인 액티비티
package com.jieun.doitmyself5_2; 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 { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imgView = findViewById(R.id.imgView); Button imgBtn = findViewById(R.id.imgBtn); imgBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { imgView.setImageResource(R.drawable.maru); } }); } }
레이아웃
<?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" tools:context=".MainActivity" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#d1180b"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#ffd400"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:layout_weight="1" android:background="#000000"> <Button android:id="@+id/imgBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="킹율 나와라" /> </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#0019f4" android:gravity="center"> <ImageView android:id="@+id/imgView" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
'Android Studio를 활용한 안드로이드프로그래밍 9판' 카테고리의 다른 글
여행지 소개 및 경비 안내 어 (2) 2024.06.14 직접 풀어보기 4-2 (0) 2024.05.03 실습 4-2 (시작함 누르고 동물 사진 나오게 하는 거) (0) 2024.05.03