프레임레이아웃

 

프레임레이아웃 안에서 자식뷰들은 등장하는 순서대로 화면에 표시된다.

 

뷰의 가시성을 제어하려면

 

android:visibility="visible"

android:visibility="invisible"

 

코드로 가시성을 제어하려면 setvisibility(View.VISIBLE); 과 같은 형태로 제어한다.

 

 

테이블레이아웃

 

일반적으로 행은 TableRow에 의해 생성되지만 일반적인 뷰 객체도 하나의 행으로 넣을수 있다.

 

예)

 

<TableLayout>

<TableRow>

<TextView android:text="주소"/>

<EditText android:text="서울시 종로구"/>

</TableRow>

</TableLayout>

<TableLayout>

<TableRow>

<TextView android:text="이름"/>

<EditText android:text="김똥개"/>

</TableRow>

</TableLayout>

 

아래와 같은 형식으로 된다. 

 

 주소

서울시 종로구 

 이름

김똥개 

 

테이블 레이아웃에서 모든셀들의 너비는 자동으로 결정

 

layout_width로 wrap_content를 지정해도 강제로 match_parent로 설정된다.

 

하지만 각 셀들의 높이는 layout_height로 지정가능

 

속성

stretchColumns 1을 넣으면 1번째 열은 내용물에 따라서 늘어날 수도 있다는것을 나타낸다.

 

shrinkColumns 열을 축소하려면 사용한다.

 

collapseColumns 열을 감추고 싶을때 사용한다.

 

 

 

블로그 이미지

왕왕왕왕

,

 

 속성

관련메소드 

설명 

orientation 

setOrientation(int) 

 horizontal은 수평 vertical은 수직 배치

gravity 

setGravity(int) 

x축과 y축 상에 자식을 어떠헥 배치할 건지 지정 

baselineAligned 

setBaselineAligned(boolean) 

false로 설정되면 자식뷰들의 기준선을 정렬하지 않는다. 

 

Gravity속성

 

 상수

 

설명 

top 

0x30 

객체를 컨테이너의 상단에 배치, 크기를 변경하지 않음 

bottom

0x50 

객체를 컨테이너의 하단에 배치, 크기를 변경하지 않음 

left 

0x03 

객체를 컨테이너의 좌측에 배치, 크기를 변경하지 않음 

right 

0x05 

객체를 컨테이너의 우측에 배치, 크기를 변경하지 않음 

center_vertical 

0x10 

객체를 컨테이너의 수직의 중앙에 배치, 크기를 변경하지 않음 

fill_vertical 

0x70 

객체를 컨테이너의 수직을 채우도록 배치 

center_horizontal

0x01

객체를 컨테이너의 수평의 중앙에 배치, 크기를 변경하지 않음 

fill_horizontal 

0x07 

객체를 컨테이너의 수평을 채우도록 배치 

center 

0x11 

객체를 컨테이너의 수평, 수직의 중앙에 배치 

fill 

0x77 

객체가 컨테이너를 가득 채우도록 배치 

 

가중치

 

android:layout_weight="1"

가중치는 정수로 표현되며 자식뷰의 중요도를 나타냄

 

가중치가 높으면 자식뷰가 부모뷰안의 비어있는 공간으로 확장할 수 있다.

 

LinearLayout의 자식뷰들의 가중치가 각각 1,2,3 이면, 남아있는 공간의 1/6, 2/6, 3/6을 할당받는다.

 

지정하지않으면 가중치는 0값을 가진 것으로 가정하고 확장되지않는다.




<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:orientation="horizontal" >


// android:orientation="horizontal" 수평

// android:orientation="vertical" 수직


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/hello_world" />


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/hello_world" />

    

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/hello_world" />

    

    <Button

        android:id="@+id/aa"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/hello_world" >

    </Button>


</LinearLayout>

 

 

 

블로그 이미지

왕왕왕왕

,

 

 레이아웃클래스

설명 

LinearLayout 

자식들을 수직이나 수평으로 배치 

TableLayout 

자식들을 테이블 형태로 배치 

GridLayout

자식들을 바둑판 모양으로 배치 

RelativeLayout 

자식들을 부모나 다른 자식에 상대적으로 배치 

TabLayout

탭을 이용하여 겹쳐진 자식중에 하나를 선택 

AbsoluteLayout 

절대 위치로 배치 

FrameLayout 

모든 자식들을 좌측상단에 겹치게 배치 

 

블로그 이미지

왕왕왕왕

,

 

 속성

설정메소드 

설명 

android:adjustviewBounds 

setAdjustViewBounds(boolean)

drawable의 종횡비를 유지하기 위하여 이미지뷰의 가로,세로를 조정

android:cropToPadding

 

true이면 패딩안에 맞추어서 이미지를 자른다. 

android:maxHeight

setMaxHeight(int) 

이미지뷰의 최대 높이 

android:maxWidth

setMaxWidth(int) 

이미지뷰의 최대 너비

android:scaleType

setScaleType(ImageViewScaleType) 

이미지 뷰의 크기에 맞추어 어떻게 확대나 축소할 것인지 방법 선택 

android:src

setImageResource(int) 

이미지소스 

android:tint 

setColorFilter(int, PorterDuff.Mode) 

이미지 배경색상 

 

 

 

블로그 이미지

왕왕왕왕

,

 

EditText는 TextView의 자식클래스이다. 중요한 속성은 다음과같다.

 

다음은 TextView클래스에서 상속받은 속성들이다.

 

속성 

설명 

android:autoText 

자동으로 타이핑오류를 교정 

android:drawableBottom 

텍스트의 아래에 표시되는 이미지 리소스 

android:drawableRight

텍스트의 오른쪽에 표시되는 이미지리소스 

android:editable

편집가능 

android:text 

표시되는 텍스트 

android:singleLine 

true이면 한줄만 받음 

android:inputType 

입력의종류 

android:hint

입력필드에 표시되는 힌트메시지 

 

inputType속성에는 다음과같은 값을 지정할수 있다.

 

 inputType

설명 

none 

편집이 불가능한 문자열 

Text 

일반적인문자열 

textMultiLine 

여러줄로 입력가능 

textPostalAddress 

우편번호 

textEmailAddress 

이메일주소 

textPassword 

패스워드 

textVisiblePassword 

패스워드 화면에 보여짐 

number 

숫자 

numberSigned 

부호가 붙으 숫자 

numberDecimal 

소수점이 있는수자 

phone 

전화번호 

datetime 

시간 

 

 

다음은 View클래스에서 상속받은 속성

 

속성

설명 

android:background 

배경이미지 리소스 

android:contentDescription 

뷰의 내용을 기술하는 텍스트 

android:id 

아이디 

android:onClick 

클릭되었을 때 호출되는 메소드 

android:visibility 

가시성 여부 

 

 

블로그 이미지

왕왕왕왕

,

 

 속성

설정메소드 

설명 

text 

setText(CharSequence) 

표시할 텍스트

textColor

setTextColor(ColorStateList) 

텍스트 색상 

textSize 

setTextSize(float) 

텍스트의크기 

textStyle

setTypeface(Typeface) 

스트스타일

(bold,italic,bolditalic) 

typeface

setTypeface(Typeface) 

텍스트폰트(normal,sans,serif,monospace) 

width 

setWidth(int) 

픽셀단위 텍스트뷰길이설정 

height 

setHeight(int) 

픽셀단위 텍스트뷰높이설정 

lines 

setLines(int) 

텍스트 뷰의 높이 설정 

 

android:text="텍스트"

android:textColor="#ff0000"

android:textSize="20pt"

android:textStyle="italic"

android:typeface="serif"

 

Button 클래스도 TextView클래스를 상속받아서 작성되어있으므로, 모든속성을 사용가능

블로그 이미지

왕왕왕왕

,

 

 

padding 속성을 사용하여 상하좌우 패딩이 설정

 

paddingLeft, paddingRight, paddingTop, paddingBottom 으로 각기 설정가능

 

패딩을 메소드로 하려면 setPadding(int,int,int,int) 메소드를 사용

 

android:padding="2pt"

 

 

 

layout_margin속성을 사용하여 상하좌우 마진을 설정

 

layout_marginLeft, layout_marginRight, layout_marginTop, layout_marginBottom 으로 각기 설정가능

 

android:layout_margin="2pt"

 

블로그 이미지

왕왕왕왕

,

 

 상수

값 

설명 

 visible

화면에보이기 디폴트값 

 invisible

표시되지않음 공간을차지함 

 gone

완전히숨김 

 

setVisibility로 제어

 

button btn = (button)findbyViewid(R.id.btn0);

 

btn.setVisibility(View.VISIBLE);

btn.setVisibility(View.INVISIBLE);

btn.setVisibility(View.GONE);

 

 

 표시방법

설명 

#RRGGBB 

RR은 빨강 GG는 녹색 BB는 청색 

 #AARRGGBB

AA는 투명도 RGB는 위와같다 

 

android:background="#ff0000"

블로그 이미지

왕왕왕왕

,