User interface programming
- xml based(xml로 사용자 인터페이스 기술)
View Group : View들을 화면에 배치하는 방법
LinearLayout(왼->오, 위->아래)
TableLayout (Table)
RelativeLayout(요소사이의 관계) : 서로 상대적인 위치를 가지고
- java based(코드로 사용자 인터페이스 작성)
Androidmanifest.xml
Androidmanifest.xml은 어플리케이션에 대한 metadata를 가지고 있다.
하나의 어플리케이션을 가지고 있고 하나의 activity를 가지고 있다. 하나 이상이 될 수도 있다.
어플리케이션이 실행되었을때 activity가 생성되면서 실행된다.
MainActivity는 onCreate 함수(생성될 때 행해지는 내용)를 재정의, 기존의 activity로써 해야하는 작업을 수행하고 setContentView를 통해 R.layout.activity_main을 화면에 배치한다.
xml기반의 UI 프로그래밍은 Layout을 설정하고 그 안에 View들을 배치한 다음 View group이나 view의 attribute를 수정하여 사용한다.
android:orientation="horizontal" or "vertical"
android:gravity = "center"
android:text = "이름"
TableLayout을 TableRow의 집합, 하나의 Row는 View들로 구성된다.
android:layout_below = "@id/TextView3"
android:layout_toRightOf = "@id/button9"
android:layout_alignParentRight = "true"
android:layout_width = "wrap_content" or "match_parent"
android:layout_height = "wrap_content" or "match_parent"
resource로 설정해두고 사용
<color name="colorBlack">#AA000000</color>
android:textColor="@color/colorBlack"
android:text = "@string/app_name"
android:visibility = ""
visible : 0 화면에 보이게 한다, 디폴트
invisible: 1 표시되지 않는다, 공간차지
gone: 2 완전히 숨겨진다. 공간 차지 안함
<계산기>
android:stretchColums="*"(공간을 꽉 채우기)
android:layout_span="3"(3개만큼을 차지하게 한다)
android:visibility="invisible"
- TextView
- EditText : TextView에다 직접 입력할 수 있는 기능성을 담은 것.
: 속성 중 inputType이 있다.
android:inputType="textPersonName"
android:inputType="number"
- ImageView : 그림을 보이게 할 수 있다.
app:srcCompat="@drawable/mario"
LinearLayout : view Group extents View
<java 코드 기반>
//activity 자체를 넣는다.
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
(LinearLayout.VERTICAL = 1)
Button button = new Button(this);
button.setText("Button");
linearLayout.addView(button);
(linearlayout이 button을 포함하고 있다와 같은 linearlayout과 button과의 관계를 설명해주지 않으면 button은 heap 공간에 떠다닌다. )
setContentView(linearLayout);
<#2>
TableLayout tableLayout = new TableLayout(this);
TextView addressTextView = new TextView(this);
addressTextView.setText("주소");
EditText addressEditText = new EditText(this);
addressEditText.setHint("주소를 입력하세요");
TableRow tableRow1 = new TableRow(this);
tableRow1.addView(addressTextView);
tableRow1.addView(addressEditText);
TableRow tableRow2 = new TableRow(this);
TableRow tableRow3 = new TableRow(this);
tableLayout.addView(tableRow1);
tableLayout.addView(tableRow2);
tableLayout.addView(tableRow3);
setContentView(tableLayout);
'study > 앱프로그래밍' 카테고리의 다른 글
[app] Activity and Intent.txt (0) | 2020.07.30 |
---|---|
[app] thread.txt (0) | 2020.07.25 |