2013-02-05 33 views
2

你好,我已经为标签代码使用布局选项卡控件在Android中,每个标签都有自己的活动,但我发现这一点:tabwidget图标对齐文本

我怎么能在红色向下移动文本圈?

这里是我的代码:

主要活动:

package com.example.androidtablayout; 

import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 

public class AndroidTabLayoutActivity extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     TabHost tabHost = getTabHost(); 

     // Tab for Photos 
     TabSpec photospec = tabHost.newTabSpec("En Vivo"); 
     photospec.setIndicator("En Vivo", getResources().getDrawable(R.drawable.icon_songs_tab)); 
     Intent photosIntent = new Intent(this, PhotosActivity.class); 
     photospec.setContent(photosIntent); 

     // Tab for Songs 
     TabSpec songspec = tabHost.newTabSpec("Twitter"); 
     // setting Title and Icon for the Tab 
     songspec.setIndicator("Twitter", getResources().getDrawable(R.drawable.icon_photos_tab)); 
     Intent songsIntent = new Intent(this, SongsActivity.class); 
     songspec.setContent(songsIntent); 

     // Tab for Videos 
     TabSpec videospec = tabHost.newTabSpec("Contactenos"); 
     videospec.setIndicator("Contactenos", getResources().getDrawable(R.drawable.icon_videos_tab)); 
     Intent videosIntent = new Intent(this, VideosActivity.class); 
     videospec.setContent(videosIntent); 

     // Adding all TabSpec to TabHost 
     tabHost.addTab(photospec); // Adding photos tab 
     tabHost.addTab(songspec); // Adding songs tab 
     tabHost.addTab(videospec); // Adding videos tab 
    } 
} 

的main.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"/> 
    </LinearLayout> 
</TabHost> 

非常感谢你。

+0

意味着ü要下来tabw​​idget或文字?即时通讯困惑什么是你的要求? – duggu

+0

下来的文字,所以它清楚地显示图标和文字,但我不知道该怎么办把文字向下移动它的可能? – alexistkd

+0

添加一些空间,以

回答

2

我已经这样做是为了使图像和文字上下对齐选项卡:

for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
      { 
       TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); 
       tv.setTextColor(Color.WHITE); 
       tv.setPadding(0, 0, 0, 5); 
       tv.setShadowLayer(2, 2, 2, Color.BLACK); 
      } 

设置填充按您的要求。

设置标签的高度:

LinearLayout.LayoutParams tab1=(LinearLayout.LayoutParams) getTabHost().getTabWidget().getChildAt(0).getLayoutParams(); 
      LinearLayout.LayoutParams tab2=(LinearLayout.LayoutParams) getTabHost().getTabWidget().getChildAt(1).getLayoutParams(); 
      LinearLayout.LayoutParams tab3=(LinearLayout.LayoutParams) getTabHost().getTabWidget().getChildAt(2).getLayoutParams(); 
      LinearLayout.LayoutParams tab4=(LinearLayout.LayoutParams) getTabHost().getTabWidget().getChildAt(3).getLayoutParams(); 
      LinearLayout.LayoutParams tab5=(LinearLayout.LayoutParams) getTabHost().getTabWidget().getChildAt(4).getLayoutParams(); 

      tab1.setMargins(10, 10, 5, 0); 
      tab2.setMargins(5, 10, 5, 0); 
      tab3.setMargins(5, 10, 5, 0); 
      tab4.setMargins(5, 10, 10, 0); 
      tab5.setMargins(0, 10, 10, 0); 
+0

在我的代码应该放在哪里?谢谢 – alexistkd

+1

后添加标签.... –

+0

的作品,但现在文本正在削减,我怎么能设置更多的高度,我的所有标签?谢谢 – alexistkd