Android- BMI 수치 계산기 만들기(2)

Code_Alpacat·2021년 11월 3일

안드로이드 기초

목록 보기
10/18

이번에 배운 것은 화면의 배치 및 세부적인 요소들을 꾸미는 것이다.

  • margin : 컴포넌트의 바깥 여백을 부여하는 기능. top, left right 등 특정한 위치에 여백을 줄 수도 있다.
  • padding : margin과 비슷하지만 안쪽 여백을 부여하는 기능.
  • textSize : dp 혹은 sp단위로 텍스트의 크기를 조절하는 기능. dp는 사용자가 임의로 바꿀 수 없다. sp는 휴대폰설정에서도 바꿀 수 있다.
  • textStyle : 글씨체를 바꿀 수 있는 기능.
  • textColor : 글자색을 바꿀 수 있다. 여기서 values -> color.xml에 컬러를 따로 추가를 해놓을 경우, 설정해놓은 이름으로도 편하게 사용이 가능하다.
  • 추가적으로, String또한 하드코드가 아니라 재사용이 필요할 땐, String.xml에 추가해주는 것이 효율적이고 편하다.
<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:padding="16dp"
    android:orientation="vertical">

    <TextView
        android:textStyle="bold"
        android:textSize="20sp"
        android:textColor="@color/custom_black"
        android:text="@string/height"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <EditText
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number" />

    <TextView
        android:textColor="@color/custom_black"
        android:textStyle="bold"
        android:textSize="20sp"
        android:layout_marginTop="30dp"
        android:text="@string/weight"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <EditText
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        />

    <Button
        android:layout_marginTop="50dp"
        android:text="확인"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>


</LinearLayout>

string.xml / color.xml

    <string name="height">신장</string>
    <string name="weight">체중</string>
  <color name="custom_black">#222222</color>
profile
In the future, I'm never gonna regret, cuz I've been trying my best for every single moment.

0개의 댓글