2013-07-23 1 views
0

나는 단편 안드로이드 애플리케이션을 개발했는데, 단편을 사용하여 탭을 구현했습니다 ...하지만 탭 이미지를 표시 할 수 없습니다 .. 아래 소스 코드를 첨부했습니다.안드로이드에서 탭에 이미지 추가하기

내 활동 클래스 TabDemoFragmentActivity.java

public class TabDemoFragmentActivity extends FragmentActivity { 

    /** 
    * Instance variable of type {@link FragmentTabHost} 
    */ 
    private FragmentTabHost fragmentTabHost; 

    /** 
    * This is a call back method, which gets invoked 
    * when the instance of this class is created. 
    * 
    * <p> 
    *  This method is used to set the tab host and 
    *  add the tab host fragments to the screen, 
    *  which acts as a UI. 
    * </P> 
    */ 
    @Override 
    protected void onCreate(Bundle bundle) { 

     super.onCreate(bundle); 

     setContentView(R.layout.activity_fragment_main); 

     fragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
     fragmentTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 

     fragmentTabHost.addTab(fragmentTabHost.newTabSpec("DropCall Details").setIndicator("DropCall Details", 
       getResources().getDrawable(R.drawable.drop_call_image)).setContent(intent), QoSDropCallDetailsFragment.class, null); 

     fragmentTabHost.addTab(fragmentTabHost.newTabSpec("Network Details").setIndicator("Network Details", 
       getResources().getDrawable(R.drawable.network_details)), QoSNetworkDetailsFragment.class, null); 
    } 
} 

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="150dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:orientation="horizontal" /> 

     <FrameLayout 
      android:id="@+id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="50" /> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</android.support.v4.app.FragmentTabHost> 

이미지가 여기에 표시 점점되지 내 XML 파일 .. 주시기 바랍니다 m ... 나 오류가 무엇인지 알려주세요 전자 탭에 이미지를 표시하는 방법을 알고 있습니다. 감사합니다

답변

0

나는 그것이 오래된 질문이지만 누군가가이 페이지에 착륙 할 수 있기를 바랍니다. 먼저, FragmentTabHost가 앱에서 탭을 추가하는 대신 사용되지 않는 접근 방식임을 지적하겠습니다. Google은 탭을 추가하기 위해 ActionTabBar로 이동하기를 원합니다.

나는 당신과 매우 비슷한 구현을했으며 많은 차이점을 보지 못했습니다. 그러나 코드에서 지적 할 수있는 두 가지 사항은 먼저, 이미지를 3 개의 드로어 블 폴더 모두에 복사해야합니다. 둘째, Framelayout이 1 개 밖에 없으므로 XML에있는 추가 Framelayout (tabcontent)을 제거하고 Activity 클래스에서 다른 하나를 사용하는 것을 보지 못합니다.

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_fragment); 
     mTabHost = (FragmentTabHost) findViewById(R.id.tabhost); 
     mTabHost.setup(this, getSupportFragmentManager(), R.id.tabFrameLayout); 

     mTabHost.addTab(
       mTabHost.newTabSpec("tab1").setIndicator("Tab 1", 
         getResources().getDrawable(R.drawable.user_card)), 
       TabActivity.ListFragment.class, null); 

     mTabHost.addTab(
       mTabHost.newTabSpec("tab2").setIndicator("Tab 2", 
         getResources().getDrawable(R.drawable.menu)), 
         TabActivity.ListFragments.class, null); 
} 
: 여기
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.app.FragmentTabHost 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/tabhost" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TabWidget 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:orientation="horizontal" /> 

    <FrameLayout 
     android:id="@+id/tabFrameLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
</LinearLayout> 

</android.support.v4.app.FragmentTabHost> 

내 활동 클래스의 조각입니다