라디오 버튼을 2줄로 표시하고 싶은데,
레이아웃을 벗어나서 그룹을 연결했더니 레이아웃 안에서 라디오 그룹을 끝내라는 에러가 나더라고요...
제가 하고싶은대로 했더니 에러가 나는 소스입니다.
라이너레이아웃을 2개를 두어서 두줄로 표현하고 그룹을 마무리지었는데
레이아웃 안에서 그룹을 마무리 지으라고 해서 2개의 그룹을 어케해야할지 걱정이네요
라이너 레이아웃을 쓰지 않고 다른 레이아웃으로 해야하나요? 그렇다면 어떤 방식으로 해야하는지도
궁금합니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:visibility="invisible" />
<RadioGroup
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:orientation = "horizontal"
android:checkedButton = "@+id/btn_dog">
<RadioButton
android:id="@+id/btn_dog"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/dog_radio"/>
<RadioButton
android:id="@+id/btn_cat"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/cat_radio"/>
<RadioButton
android:id="@+id/btn_ham"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/ham_radio"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:visibility="invisible" />
<RadioButton
android:id="@+id/btn_fish"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/fish_radio"/>
<RadioButton
android:id="@+id/btn_bird"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/bird_radio"/>
<RadioButton
android:id="@+id/btn_snake"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/snake_radio"/>
</RadioGroup>
</LinearLayout>
라이너가 뭔가 했더니 리니어레이아웃 말씀하시는거였네요
그리 어려운 문제는 아닙니다.
가로, 세로로 배치하는것은 리니어 레이아웃의 Orientation 옵션을 변경하여 바꿀 수 있습니다.
라디오 그룹도 마찬가지로 Orientation 옵션이 있어 가로로, 혹은 세로로 배치하여 사용 할 수 있습니다.
안에 다른 레이아웃을 넣어서 ㄱ자 같이 배치를 할 수도 있구요.
버튼의 크기가 일정하지 않게 나오는 문제는 weight 옵션을 주어 극복할 수 있습니다.
의도하시는 레이아웃이 뭔지는 잘 모르겠으나 임의로 짜 보았습니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="80dp"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:visibility="invisible" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checkedButton="@+id/btn_dog"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/btn_dog"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/dog_radio" />
<RadioButton
android:id="@+id/btn_cat"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/cat_radio" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/btn_ham"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:src="@drawable/ham_radio" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
위의 적어주신 소스로 돌렸더니
ㄱ의 라디오버튼이 나와서 제가 원하는 문제가 해결이 되었는데,
가로줄의 버튼은 정상작동하나 세로줄의 버튼은 상호 연결이 안된듯 혼자만 각자 인식이 됩니다.
라디오 버튼 특성상 하나를 누르면 나머지가 모두 꺼져야되는데 말이죠....
어째서 이런 현상이 발생하는 것일까요??
그리고 weight 도 검색해보았는데, 거기에 어떤 값을 줘도 버튼의 크기가 바뀔 생각을 하지않고 이상하네요
이 부분은 조금 더 공부해서 수정해보겠습니다. 일단 답변 달아주신 소스에 대한 질문부터 부탁드릴게요 ㅠㅠ 감사합니다




찾아보니 펍에도 같은 동일 질문이 여러개 있는데 전부 답변이 없는거보니 쉬운 문제는
아닌거같네요. 포탈에서도 같은 문제로 고민하는 질문을 여러 개 봤는데 다 답변이 없고요..
저렇게 하지 않고 그냥 1자로 구성해봤는데, 이래도 문제가 생기는 것이...
왜 버튼 크기가 이상할까요??? 그냥 이미지버튼으로 했을때에는 아무렇지도 않았는데
라디오버튼으로 하니까 버튼이 이상해졌습니다. 조금 검색해보니
radio 버튼의 크기는 정해져있어서 이미지 교환시에도 안맞는다는 말이 있던데...
이 부분은 무슨 문제인지 알고싶네요.. 이미지가 딱 맞지않고 잘리게 나옵니다. 사이즈를 수정해도요.