일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- Reanimated
- Android
- React-native
- React
- IOS
- react-naive-gesture-handler
- React Native
- Animated
- PanResponder
- Today
- Total
개발자포럼
뷰의 개요 본문
앱 실행 화면을 구성하는 요소를 통칭하여 뷰라고 함
텍스트, 버튼 등 모두 뷰에 속함
다른말로 위젯(Widget)이라고 하며 뷰 클래스 하위의 모든 클래스를 지칭하기도 함
다른 위젯을 담을 수 있는 위젯을 특별히 레이아웃이라고 한다.
레이아웃은 위젯들을 포함하는 컨테이너 역할을 함.
View 클래스 속성
ID
id를 지정하고 지정한 id에 대한 객체를 가져와서 사용
<Button
android:id="@+id/btnClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="세상아 안녕!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Button button = (Button) findViewById(R.id.btnClick);
layouy_width, layout_height
위젯의 폭과 높이를 나타냄
-match_parent
≒ fill_parent
자신의 부모에 폭이나 높이를 맞춘다는 의미
-wrap_content
자신의 폭이나 높이를 자신 글자가 꼭 들어갈 정도만 설정한다는 의미
<Button
android:layout_width:"120dp"
android:layout_height:"240dp"/>
dp는 화면 밀도에 독립적으로 사용되는 단위
-> 해상도에 따라 같은 비율로 출력되는 효과
background
위젯의 색상을 16진수 여섯 개로 설정
android:background="#00FF00"
padding
위젯의 경계선으로부터 위젯 안의 요소가 떨어지도록 설정
layout_margin
위젯과 위젯 사이에 여백 설정
visibility
위젯을 보일 것인지 여부를 설정
-visible 보임
-invisible 자리 유지
-gone 유지 안 함
enabled
위젯의 동작 여부 설정 boolean
clickable
클릭이나 터치가 가능하도록 설정 boolean
rotation
위젯을 회전시켜서 출력, 값은 각도로 지정
TextView
ㄴEditText, Button 등
속성
text
textColor
textSize
password
inputType
gravity
보통 EditText에서 값을 가져올경우
EditText edit = (EditText)findViewByid(R.id.edittext1);
String str = edit.getText().toString();
CompoundButton
ㄴ CheckBox, RadioButton, Switch, ToggleButton
라디오버튼은 라디오그룹과 함께 사용하고, 반드시 id 속성을 사용해야함
CompoundButton이 체크가 되었을경우 확인하는 방법
CheckBox myCheck = (CheckBox) findViewById(R.id.android);
// onClick 으로 체크 여부 확인방법
myCheck.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
if(((CheckBox) v).isChecked())
{
// 체크유무 검사
}
}
});
//onCheckedChangeListener 으로 체크 여부 확인방법
myCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChagneListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
{
// 체크유무 검사
}
}
});
ImageView
ㄴ ImageButton
그림을 출력하는 위젯
모든 속성은 Java 코드에서도 설정가능하며
헤딩 클래스에 .set속성 으로 설정할수있다.
Android 개발자 가이드에서 더 많은 레이아웃, 뷰 정보를 얻을 수 있다.
https://developer.android.com/guide?hl=ko
개발자 가이드 | Android 개발자 | Android Developers
Android 개발자 가이드에 오신 것을 환영합니다. 왼쪽 탐색에 나열된 문서에서는 Android 프레임워크와 다른 라이브러리에서 API를 사용하여 Android 앱을 빌드하는 방법을 알려줍니다. Android를 처음 접하고 바로 코드 작성에 들어가고 싶다면 첫 앱 빌드 가이드로 시작하세요. 다음의 리소스도 확인하여 Android 개발에 관해 알아보세요. Codelab: 각각 별개의 주제를 다루는 짧은 자기 주도형 가이드입니다. 대부분의 Codelab에서
developer.android.com
'Android' 카테고리의 다른 글
기본구조, Activity 생성 (0) | 2020.04.12 |
---|