현제 layout으로 아래와같은 형태의 ui를 구현하려 합니다.
________
hello
ㅁㅁ
ㅁㅁ
ㅁㅁ
ㅁㅁ
ㅁ
--------------
<세로모드 화면>
현제 제가 사용한 방법으로 하면 정확하게 비율이 맞지 않습니다.
여기서 정확한 비율이란 hello와 아래 4줄(2열로 버튼이 있음)의 버튼들과 마지막줄 버튼하나의 높이가 모두 같아야 한다는거죠
제 생각은
<LinearLayout
android:orientation="vertical">
<TextView
android:layout_weight="1"
android:text="hello">
<LinearLayout
android:orientation="horizontal"
android:layout_weight="4">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1">
<Button
android:layout_weight="1"/>
이후 3개의 버튼을 더 생성...
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1">
<Button
android:layout_weight="1"
이후 3개의 버튼을 더 생성...
</LinearLayout>
</LinearLayout>
<Button
android:layout_weight="1"/>
</LinearLayout>
이와같은 식으로 구성했습니다.
즉 최초 레이아웃을 vertical로 잡아준후
hello 텍스트를 입력하고
이후 레이아웃을 horizontal로 잡아준후
내부에 레이아웃 2개를 vertical로 생성시킵니다.
이제 4개의 버튼을 위 2개의 레이아웃에 생성시키면 총 8개의 버튼이 4행2열로 존재하게 되겠죠?
이후 최종 레이아웃으로 나가 다시 버튼 하나를 생성시킵니다.
이렇게 할려고 하는데 비율이 잘 맞지 않거나 혹은 text가 지워지거나하는 이상한 문제점이 생깁니다.
어떻게 해야할까요??
예를들어 layout_weight같은 경우는 최상단 LinearLayout이 fill_parent이고 내부의 TextView가 1 LinearLayout이 4 Button이 1이니까
화면의 세로길이를 6등분해서 1:4:1로 사용하는게 맞는것 아닌가요? 테스트결과 스크롤도 안되었습니다.
실제 소스는 아래와 같습니다.
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:orientation="vertical"
5 android:layout_width="fill_parent"
6 android:layout_height="fill_parent">
7 <TextView
8 android:layout_width="fill_parent"
9 android:layout_height="wrap_content"
10 android:layout_weight="1.0"
11 android:text="Nand Flash"
12 android:id="@+id/Activiti_2_text"/>
13 <LinearLayout
14 android:orientation="horizontal"
15 android:layout_width="fill_parent"
16 android:layout_height="fill_parent"
17 android:layout_weight="4.0">
18 <LinearLayout
19 android:orientation="vertical"
20 android:layout_width="fill_parent"
21 android:layout_height="fill_parent"
22 android:layout_weight="1.0">
23 <Button
24 android:layout_width="fill_parent"
25 android:layout_height="fill_parent"
26 android:layout_weight="1.0"
27 android:text="Prev"
28 android:id="@+id/terminateActivity"/>
29 <Button
30 android:layout_width="fill_parent"
31 android:layout_height="fill_parent"
32 android:layout_weight="1.0"
33 android:text="Prev"
34 android:id="@+id/terminateActivity"/>
35 <Button
36 android:layout_width="fill_parent"
37 android:layout_height="fill_parent"
38 android:layout_weight="1.0"
39 android:text="Prev"
40 android:id="@+id/terminateActivity"/>
41 <Button
42 android:layout_width="fill_parent"
43 android:layout_height="fill_parent"
44 android:layout_weight="1.0"
45 android:text="Prev"
46 android:id="@+id/terminateActivity"/>
47 </LinearLayout>
48 <LinearLayout
49 android:orientation="vertical"
50 android:layout_width="fill_parent"
51 android:layout_height="fill_parent"
52 android:layout_weight="1.0">
53 <Button
54 android:layout_width="fill_parent"
55 android:layout_height="fill_parent"
56 android:layout_weight="1.0"
57 android:text="Prev"
58 android:id="@+id/terminateActivity"/>
59 <Button
60 android:layout_width="fill_parent"
61 android:layout_height="fill_parent"
62 android:layout_weight="1.0"
63 android:text="Prev"
64 android:id="@+id/terminateActivity"/>
65 <Button
66 android:layout_width="fill_parent"
67 android:layout_height="fill_parent"
68 android:layout_weight="1.0"
69 android:text="Prev"
70 android:id="@+id/terminateActivity"/>
71 <Button
72 android:layout_width="fill_parent"
73 android:layout_height="fill_parent"
74 android:layout_weight="1.0"
75 android:text="Prev"
76 android:id="@+id/terminateActivity"/>
77 </LinearLayout>
78 </LinearLayout>
79 <Button
80 android:layout_width="80px"
81 android:layout_height="fill_parent"
82 android:layout_weight="1.0"
83 android:layout_gravity="center_horizontal"
84 android:text="EXIT"
85 android:textSize="16px"
86 android:id="@+id/launchExitActivity"/>
87 </LinearLayout>
그리고 출력되는 결과는 아래의 첨부한 파일과 같습니다.
어떻게 해야 할까요??
버튼들이 들어간 레이아웃의 높이를 같은 높이로 만들고, 그 안에 버튼들을 fill_parent로 만들면 문제 없을거 같은데요.
TextView와 맨 아래의 버튼에 weight를 빼고 height를 고정값으로 넣으니 어느정도 원하는 화면은 나왔습니다.
근데 궁금증이 생기네요 정확히 weight의 의미가 몬지 모르겠습니다. 같은 범주에 있는 객체들(여기서는 TextView와 LiearLayout horizontal과 마지막 버튼)의 비율을 1:4:1로 해주고 fill_parent를 주면 알아서 나뉘어서 분류되어야 하는것 아닌가요?
LinearLayout TextView나 Button과 같은 view와는 동일하게 적용할 수 없는건가요??