안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요,
연습삼아 어플 개발중에..
화면 하단에 버튼 다섯개를 배치하여 메뉴 버튼으로 쓰려고 합니다.
근데 버튼 크기가 weight 값을 주더라도 버튼에 쓰인 텍스트 길이에 의해 중구난방으로 변해버립니다.
특히나 5개의 메뉴중에 2번 메뉴 버튼을 클릭하면,
2번 버튼은 사라지고(공백이 버튼 크기만큼 생기고)
남은 4개의 버튼만 보이게 하려고 하는데..
버튼이 안보이게 하는건 문제가 아니나, 공백의 크기가 매우 작아집니다.
TableLayout도 써보고, LinearLayout도 써보고.. 이래저래 해봤으나..
도무지 방법이 안보이네요..
혹시 가능한 방법이 있을까요?? 도움 부탁드립니다!
연습삼아 어플 개발중에..
화면 하단에 버튼 다섯개를 배치하여 메뉴 버튼으로 쓰려고 합니다.
근데 버튼 크기가 weight 값을 주더라도 버튼에 쓰인 텍스트 길이에 의해 중구난방으로 변해버립니다.
특히나 5개의 메뉴중에 2번 메뉴 버튼을 클릭하면,
2번 버튼은 사라지고(공백이 버튼 크기만큼 생기고)
남은 4개의 버튼만 보이게 하려고 하는데..
버튼이 안보이게 하는건 문제가 아니나, 공백의 크기가 매우 작아집니다.
TableLayout도 써보고, LinearLayout도 써보고.. 이래저래 해봤으나..
도무지 방법이 안보이네요..
혹시 가능한 방법이 있을까요?? 도움 부탁드립니다!
2009.09.08 09:38:54
아.. 자답입니다.
TableLayout 으로는 도저히 답이 안나오는것 같습니다. 그리고 LinearLayout을 쓰되
layout_width 을 fill_parent 로 주고, 각각의 버튼에 weight 값을 1로 주고, 안보이게 할 버튼들을 invisible 로 설정해주면 되네요.
혹시라도 다른 보이는 버튼들에 줄바꿈이라도 들어있다면 안보일 버튼들에도 최소한 줄바꿈 정도는 text로 넣어줘야 하네요.
예를 들자면 이런식입니다.
<LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal"> <Button android:id="@+id/blank_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="\n" android:visibility="invisible"/> <Button android:id="@+id/blank_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="\n" android:visibility="invisible"/> <Button android:id="@+id/blank_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="\n" android:visibility="invisible"/> <Button android:id="@+id/my_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="@string/ok_button"/> <Button android:id="@+id/my_button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:text="@string/cancel_button"/> </LinearLayout>
제가 했던 실수는 버튼들의 width를 wrap_content 로 주고, weight값을 줬다거나, fill_parent로 주고 weight 값을 안줬다거나..
tablelayout으로 잡았다거나.. 이런것들이었습니다.
휴.. 레이아웃 잡는게 젤 어려운거 같네요 ㅜ.ㅜ 어쨌거나 이번기회에 하나 더 배웠습니다. 각각의 property 를 제대로 이해하고
쓰는게 참 중요한거 같네요.
회색님 향긋한소리님 답변 감사드립니다.!!