2011-09-23 10 views
1

각 탭의 목록으로 TabActivity를 테스트하고있었습니다.Android : tabactivity - 처음에는 모든 탭의 내용이 겹치다

앱을 실행하는 동안 탭의 내용이 이렇게 겹칩니다. enter image description here

내가 탭을 클릭하면 오버랩이 지워집니다.

testtabs.xml 레이아웃 :

<?xml version="1.0" encoding="utf-8"?> 
<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <ListView 
       android:id="@+id/list1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"> 
      </ListView> 
      <ListView 
       android:id="@+id/list2" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"> 
      </ListView> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

그리고 테스트 활동

public class TabbedActivity extends TabActivity { 

    private static final String LIST1_TAB_TAG = "List1"; 
    private static final String LIST2_TAB_TAG = "List2"; 
    private ListView listView1; 
    private ListView listView2; 
    private TabHost tabHost; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.testtabs); 
     tabHost = getTabHost(); 

     // setup list view 1 
     listView1 = (ListView) findViewById(R.id.list1); 
     // create some dummy strings to add to the list 
     List<String> list1Strings = new ArrayList<String>(); 
     list1Strings.add("List 11"); 
     list1Strings.add("List 12"); 
     list1Strings.add("List 13"); 
     list1Strings.add("List 14"); 
     listView1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings)); 

     // setup list view 2 
     listView2 = (ListView) findViewById(R.id.list2); 
     List<String> list2Strings = new ArrayList<String>(); 
     list2Strings.add("Test2 List 21"); 
     list2Strings.add("Testing 22"); 
     list2Strings.add("More test 23"); 
     list2Strings.add("Test Again 24"); 

     listView2.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list2Strings)); 

     // add views to tab host 
     tabHost.addTab(tabHost.newTabSpec(LIST1_TAB_TAG).setIndicator(LIST1_TAB_TAG).setContent(new TabContentFactory() { 
      public View createTabContent(String arg0) { 
       return listView1; 
      } 
     })); 
     tabHost.addTab(tabHost.newTabSpec(LIST2_TAB_TAG).setIndicator(LIST2_TAB_TAG).setContent(new TabContentFactory() { 
      public View createTabContent(String arg0) { 
       return listView2; 
      } 
     })); 
     tabHost.setCurrentTab(0); 
    } 
} 

답변

3

당신은 XML 레이아웃에서 모두의 ListView를 제거 할 수 있습니다 그냥 자바 코드를 생성,이 같이있는 LinearLayout 내부에있는 ListView의 유지.

listView1 = 새로운 ListView (this);

모든 것이 정상입니다.

+0

그것은 친구를 일했다 ..... – gtiwari333

1

당신은 당신의 오버 랩핑에 대한 이유입니다 FrameLayout이 두 가지의 ListView의 복용 다음은 내 코드입니다.

당신이 다른 아래 하나의 ListView를해야합니다

<?xml version="1.0" encoding="utf-8"?> 
<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
      <ListView 
       android:id="@+id/list1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"> 
      </ListView> 
      <ListView 
       android:id="@+id/list2" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"> 
      </ListView> 
      </LinearLayout> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 
+0

없음. 하나의 목록보기가 각 탭에 나타나길 원합니다. tab1의 list1, tab2의 list2 등. 나는 너의 레이아웃을 시도했다. 처음에는 두 개의 목록을 표시합니다 (첫 번째 탭). 탭을 클릭하면 각 탭에 단일 목록이 나타납니다. – gtiwari333

+1

http://www.androidpeople.com/android-tabhost-tutorial-part-1이 자습서 참조 –

+0

@Lalit : 정말요? 이 자습서는 문제와 관련이없는 것으로 보입니다! –

2

내가 찾은 또 다른 솔루션은 레이아웃 XML 파일에서의 ListView 모두에 다음 태그를 추가하는 것입니다

android:visibility="invisible" 
관련 문제