본문으로 바로가기

4. 기본 위젯

category 프로그래밍/안드로이드 2017. 11. 25. 01:14

1.  Button 위젯

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

리니어 레이아웃(가장 많이 쓰임 표준이라고 볼수있겠다.박스형 모델)
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" // 무조건 남아 있는 공간을 채움... 여기서는 뷰의 가로 폭을 다 채운다는 의미
android:layout_height="match_parent" // 내용물 크기에 따라 뷰의 크기를 결정..여기서서는 뷰의 높이를 내용물 크기에 따라 결정
android:background="#cccccc" 배경설정
android:gravity="center" // 리니어 레이아웃의 요소 내용물을 정렬... 여기서는 버튼2개를 모두 중앙에 정렬하겠다는 의미
android:orientation="vertical" >// 뷰의 정렬방향을 수직방향으로 정렬


<Button
android:id="@+id/button1" //id 속성값
android:layout_width="200px"
android:layout_height="200px"
android:background="#ff0000"
android:gravity="bottom|right" //'|'표시는 복수값을 나타내며 오른쪽방향으로 바닥끝에 위치
android:layout_marginBottom="50px" ///상하좌우의 값을 통틀어서 전체 값을 조정한다.
android:text="button1" />

<Button
android:id="@+id/button2"
android:layout_width="100px"// 100픽셀만큼의 길이조정
android:layout_height="100px"
android:background="#ff0000"
android:gravity="bottom|center_horizontal" // 수직방향으로 중앙에위치하는데 바닥끝으로 정렬
android:text="button1" />

</LinearLayout>


참고


top

bottom

left

right

cetter

center_Vertical : 객체를 수직방향의 중앙에 배치

center_horizntal : 객체를 수평방향의 중앙에 배치

margin: 객체 주위에 있는 상하좌우의 값을 얼마만큼 값을 주는것 10px이면 10px만큼 떨어져 배치

padding: 안쪽여백에 있는 요소를 상하좌우 값을 지정하여 떨어지게 하는 것

<TextView:텍스트를 화면에 보여줌
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20px"
android:text="ABCDEF"
android:textColor="#ffffff"
android:textSize="20px"
android:textStyle="bold" : 기울

<EditText : 사용자의 입력을 받고자 할때
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="이름을 입력하세요."
/>


<ImageView : /res/drawable-xxx에 이미지가 저장된다. 그것을 사용하기 위해서는 src라는 속성을 이용하여 경로를 지정해야한다.


android:layout_width="match_parent"

android:layout_height="wrap_content'

android:src="@drawable/ic_launcher_background


'프로그래밍 > 안드로이드' 카테고리의 다른 글

3. 레이아웃  (1210) 2017.11.24
2.안드로이드 프로젝트 만들기  (1189) 2017.11.21
1.안드로이드 개요 및 개발환경 구축  (1886) 2017.11.20