본문 바로가기
프로그래밍/안드로이드

#11.안드로이드 ImageView, Checkbox

by -현's- 2023. 1. 23.
반응형
ImageView

- 이미지를 노출할때 사용하는 뷰이다.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity2">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/a"></ImageView>



</androidx.constraintlayout.widget.ConstraintLayout>

 

반응형
Checkbox

-TextView의 서브 클래스라서 TextView에 설정하는 속성값 사용가능하다.

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main2);

        CheckBox chk1 = (CheckBox) findViewById(R.id.chk1) ;
        chk1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    chk1.setText("체크박스 ㅇ");
                }else{
                    chk1.setText("체크박스 X");
                }

            }

        }) ;

    }
}

 

반응형

댓글