현재 Android 탭 (3.1)의 하단에 탭이있는 사용자 인터페이스를 구현하려고합니다. 그러나 여러 가지 방법이 있다는 것을 알고 있습니다. 왜냐하면 저는 저에게 맞는 것을 찾지 못해서 라디오 버튼을 사용하려고합니다. 아이디어는 각 탭이 라디오 버튼 (현재 텍스트 없음)이라는 것입니다.가변 폭의 Android 라디오 버튼
이 레이아웃은 다음과 같이 가정한다 : 화면 상단에서
와서 조각의 컨테이너 역할을하는 FrameLayout이있다.
해당 컨테이너 아래에는 각 라디오 버튼이 탭으로 작동하는 가로 라디오 그룹이 있습니다. 활성 탭 (라디오 버튼)은 상단의 다른 탭과 겹치기 때문에 어떤 탭이 활성 상태인지 분명합니다. 라디오 버튼이 탭처럼 작동하려면 android : button 속성을 statelistdrawable로 설정하십시오. statelistdrawable에는 활성 상태와 비활성 상태에 대한 두 개의 이미지가 포함되어 있습니다 (불행히도 아직 이미지를 게시 할 수 없습니다). 활성 탭의 이미지가 비활성 탭 중 하나보다 크기 때문에 (너비가) 내 아이디어는 onClickListener에서 bringToFront() 메서드를 사용하여 활성 탭 (또는 라디오 버튼)이 탭을 왼쪽으로 겹치게하는 것이 었습니다 그리고 그것의 권리.
내 레이아웃 파일은 다음과 같습니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- container for the fragments -->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:layout_weight="0" />
<!-- container for the tabs realized with radio buttons -->
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_weight="1" >
<!-- tabs -->
<RadioButton android:id="@+id/tab_1"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_2"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_3"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_4"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_5"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
</RadioGroup>
</LinearLayout>
과 statelistdrawable XML 파일은 다음과 같습니다 : 내가 설정에도 불구하고
- :
불행히도 나는 두 가지 문제가 발생 0으로 framelayout의 layout_weight 및 tho를 둘러싼 선형 레이아웃 내에서 radiogroup 중 하나가 1로 설정됩니다. 두 번째, framelayout 전체 화면을 차지합니다.<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" android:constantSize="false"> <item android:state_checked="false" android:drawable="@drawable/tab_inactive" /> <item android:state_checked="true" android:drawable="@drawable/tab_active" /> </selector>
- 디버깅을 위해 framelayout의 높이를 0으로 설정하면 탭이 표시됩니다. 그러나 너비에 걸쳐 균등하게 분포되어 있지는 않지만 서로 겹쳐져 있고 왼쪽에 약간 짜 맞춰져 있습니다. 라디오 버튼의 너비를 비활성 탭에 사용되는 이미지의 너비 (px)로 설정하면 탭이 균등하게 정렬됩니다. 그러나 탭 중 하나를 클릭하면 활성 탭에 대한 탭 이미지가 변경되고 statelistdrawable의 android : constantSize 속성을 false로 설정하더라도 버튼이 오른쪽 또는 왼쪽 버튼과 겹치지 않습니다. , 오른쪽으로 이동합니다.
누구나 이러한 문제에 대한 해결책을 얻었습니까? 특히 상대적인 차원을 사용하는 사람이 있습니까? 이것은 나의 첫 번째 게시물이며, 제 질문이 정교하거나 충분히 elaborte면 사전에 사과드립니다. 절 믿으세요. 저는 (예를 들어 절대 크기를 사용하여) 이러한 문제를 해결하기 위해 지금 여러 해 동안 노력해 왔습니다. 어떤 도움이라도 크게 평가 받게 될 것입니다!
저는 제 2 번째 문제에 대한 해결책을 찾았습니다. 탭 (라디오 버튼)과 탭이 활성화 된 상태에 따라 다른 상태에 대해 levelListDrawable을 사용하는 조각 사이에 분리 막대를 삽입했습니다. 첫 번째 문제에 대한 답변 – Schnodahipfe
을 남겨주세요. http : //stackoverflow.com/questions/1958388/android-simple-linearlayout-and-fill-parent-question – Schnodahipfe