초보 개발자의 기록

GUI 컴포넌트 종류와 이용 본문

Android

GUI 컴포넌트 종류와 이용

bambinodeveloper 2021. 1. 23. 00:11
728x90

버튼, TextView(라벨), editText(텍스트박스), Radio, Scroll, ImageView...

 

LinearLayout = java의 flowLayout과 흡사

 

MainActivity.java

package com.study.app0119;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        //화면에 버튼 나오게 하자

        //Alt+Enter = import
        Button bt = new Button(this);
        bt.setText("나의 첫 버튼");

        //화면에 부착
        //this.setContentView(bt);
        
        //로컬 pc가 아닌 스마트폰이므로, 드라이브를 지정할 수 없으므로 
        //정해둔 res 디렉토리 밑에서 찾아갈 수 있도록하자
        //res를 R.java 파일로 관리
        //파일이름은 상수로 관리 - 실시간으로 등록되어있음
        this.setContentView(R.layout.linear); //레이아웃 xml의 경로 및 파일명

        //결론: 응용어플리케이션에서는 화면 배치가 중요하다
    }
}

linear.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="난 버튼" />
</LinearLayout>

 

이미지는 소문자로 시작, 숫자로시작 불가능, drawable에 위치

linear.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFC107"
    android:orientation="vertical">
    <!--
    리니어 레이아웃은?
    선형레이아웃으로써, 내부의 자식 컴포넌트들을 일렬로 배치
    일렬 방향은 두 가지
    1> 수직 :Vertical
    2> 수평 :Horizontal
    -->

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="난 버튼" />

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

    <!--텍스트 입력-->
    <!-- hint = placeholder-->
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="여기에 텍스트 입력"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:hint="여기에 연락처 입력"/>

    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Switch"/>

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox"/>

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <SurfaceView
        android:id="@+id/surfaceView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

728x90
반응형

'Android' 카테고리의 다른 글

첫 버튼 생성  (0) 2021.01.22
Android Studio 기본 설명  (0) 2021.01.22
안드로이드 설명  (0) 2021.01.22
안드로이드-개발환경 구축  (0) 2021.01.22