2013-12-12 34 views
1

在此先感謝。這裏有一些代碼和圖像。我的選項卡中的圖像是拉伸的,看起來不太好。我可以如何「拉伸」它?

這是圖像。 http://s904.photobucket.com/user/fookywooky/media/sof_zpsb7c18f62.png.html

這是我在主要活動代碼(的onCreate)

@Override 
protected void onCreate(Bundle savedInstanceState) { 


    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    hostTab = (TabHost) findViewById(R.id.tabhost); 
    hostTab.setup(this.getLocalActivityManager()); 

    //setting tabs(images) 
    mIntent = new Intent(this, HomeActivity.class); 
    specTab = hostTab.newTabSpec("home").setIndicator(" ",getResources().getDrawable(R.drawable.home_tab)).setContent(mIntent); 
    hostTab.addTab(specTab); 
    hostTab.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.home_tab); 
    //hostTab.getTabWidget().getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(150,50)); 

    mIntent = new Intent(this, ContactUsActivity.class); 
    specTab = hostTab.newTabSpec("contactUs").setIndicator(" ",getResources().getDrawable(R.drawable.contact_us_tab)).setContent(mIntent); 
    hostTab.addTab(specTab); 
    hostTab.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.contact_us_tab); 

    mIntent = new Intent(this, TravelDetailsActivity.class); 
    specTab = hostTab.newTabSpec("travelDetails").setIndicator(" ",getResources().getDrawable(R.drawable.travel_details_tab)).setContent(mIntent); 
    hostTab.addTab(specTab); 
    hostTab.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.travel_details_tab); 

    mIntent = new Intent(this, PortGuide.class); 
    specTab = hostTab.newTabSpec("portGuide").setIndicator(" ",getResources().getDrawable(R.drawable.port_guide_tab)).setContent(mIntent); 
    hostTab.addTab(specTab); 
    hostTab.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.port_guide_tab); 

    mIntent = new Intent(this, MoreMenu.class); 
    specTab = hostTab.newTabSpec("more").setIndicator(" ",getResources().getDrawable(R.drawable.more_tab)).setContent(mIntent); 
    hostTab.addTab(specTab); 
    hostTab.getTabWidget().getChildAt(4).setBackgroundResource(R.drawable.more_tab); 

} 

這是home_tab.xml

<?xml version="1.0" encoding="utf-8"?> 

<item 
    android:state_selected="true" 
    android:drawable="@drawable/home_blue"> 
</item> 
<item 
    android:drawable="@drawable/home_gray"> 
</item> 

這是主要活動的XML

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:id="@+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"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="bottom"> 
     </TabWidget> 

    </LinearLayout> 
</TabHost> 

在advaance請help.Thanks

+1

附上關於「拉伸」圖像的外觀以及您希望它看起來如何的截圖。 –

+0

對不起。我忘了放圖片鏈接,並感謝回覆。 – androidNoob

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:id="@+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"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 
     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="bottom"> 
     </TabWidget> 

    </LinearLayout> 
</TabHost> 

嘗試直接使用圖像到您的ID標籤控件,所以要工作

編輯:

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp" 
    android:orientation="vertical"> 
    <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    </FrameLayout> 
</LinearLayout> 
+0

感謝您的回覆。但是你能告訴我我該怎麼做嗎?我是新來的android編程。:) – androidNoob

+0

正如Vipul Purohit所說,添加屏幕截圖然後它很容易說出如何。 – kathir

+0

Screenshot is already up.Thanks。 – androidNoob