- 프레임레이아웃은 단순한 레이아웃이다.- 하나의 뷰만을 화면에 표시한다. 프레임 레이아웃은 중첩기능을 가지고 있는데, 뷰를 하나 이상 추가 할 경우에 추가된 순서대로 쌓이는 특징을 가지고 있다.가장 먼저 추가한 뷰가 아래쪽에 쌓이며, 가장 나중에 추가한 뷰만 보이게 되는데, 이때 뷰의 가시성 속성(visibility)을 가지고 설정을 하게 되면 추가한 여러개의 뷰를 서로 전환하면서 보여줄 수 있다. 다음은 프레임 레이아웃으로 버튼을 클릭했을 때 이미지를 순서대로 보여주는 코드이다. 이미지가 더 이상 없을 때에는 처음으로 돌아가서 마지막에 추가한 뷰 순서대로 이미지를 다시 보여준다.-xml코드 visibility로 가시성 속성을 설정할 수 있으며, visible은 보여주는 값이고, invisible은 보..
테이블레이아웃은 엑셀시트 처럼 격자 형태의 행과 열로 구성된다. 테이블레이아웃 엘리먼트 안에는 TextRow라는 엘리먼트가 들어 갈 수 있는데, 하나의 TextRow는 하나의 행(가로)을 나타낸다. 그리고 하나의 TextRow안에 쌓이는 뷰는 Horizontal 방향으로 배치된다. 테이블레이아웃 엘리먼트에서 설정 할 수 있는 대표적인 속성으로 shrinkColumns와 stretchColumns가 있다.shrinkColumns : 부모 컨테이너의 폭에 맞추도록 각 열의 폭을 강제로 축소stretchColumns : 부모 컨테이너의 공간을 채우기 위해 지정된 뷰의 열의 폭을 자동 조절해서 늘린다. 테스트 TableRow의 높이값인 TableLayout의 layout_height는 항상 wrap_conten..
람다식은 메서드를 하나의 식(expression)으로 표현한 것.람다식을 '익명 함수'라고도 한다. 람다식의 기본 구문은 다음과 같다. //일반적인 메서드의 형식 int sum(int a, int b){ return a+b; } //람다식을 사용한 경우 (int a, int b) -> { return a+b; }; 메서드 선언부의 메서드명이 없어지고 선언부와 구현부 사이에 화살표 표시가 존재한다. 람다식은 그 자체는 메서드 모습을 하고 있지만 엄밀히 말하면 익명 클래스의 객체와 같다고 볼 수있다. Test t = new Test(){ int sum(int a, int b){ return a+b; } }; 익명 클래스의 객체라는게 위에서 보는 것 처럼 인스턴스 생성 즉시 그 클래스 타입의 멤버를 바로 기술..
layout_gravity : 대상이 되는 뷰의 부모 컨테이너의 공간에서의 위치를 정렬할 때 사용gravity : 뷰안의 내용을 정렬할 때 사용(텍스트뷰는 글자가 내용이 되고, 이미지뷰는 이미지가 내용이 됨) 먼저 gravity를 테스트 해본다. super.onCreate(savedInstanceState); //리니어 레이아웃 인스턴스 생성 후 뷰들을 배치할 방향을 설정 LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); //(vertical,horizonal) //생성한 레이아웃에 들어갈 속성을 결정할 파라미터 생성(가로,세로) LinearLayout.LayoutParams params =..
안드로이드 프로그램을 구성하는 주요 컴포넌트(구성요소,부품)는 액티비티(Activity)다. 그러나 액티비티는 화면에 직접적으로 사용자에게 보이지 않고 실제 사용자가 보게되는 것은 뷰(View)이다. 뷰 여러개가 모여서 액티비티가 되고, 액티비티 여러개가 모이면 안드로이드 응용 프로그램이 된다. 뷰는 2가지로 나뉜다.1. 위젯(Widget) : 버튼, 텍스트 뷰, 에디트 등이 위젯이며 흔히 컨트롤(Control)이라고도 한다.2. 뷰그룹(ViewGroup) : 직접적으로 보이지 않으며 뷰(View)를 담는 컨테이너 역할을 한다. 뷰란?- 안드로이드에서의 뷰란 컨트롤과 위젯을 지칭하는데...버튼, 텍스트, 이미지 등이 이에 해당한다. 이들은 모두 View클래스로 부터 상속되어 저마다의 클래스 형태로 존재한..