2011-01-09 34 views
1

嘿,我已经设置了一个选项卡布局,以便每个选项卡都是我的自定义位图。这是主要的Java文件:把位图选项卡放在任何位置

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


    Resources res = getResources(); 
    TabHost tabHost = getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 

    intent = new Intent().setClass(this, ArtistsActivity.class);  
    ImageView imgView1 = new ImageView(this); 
    BitmapDrawable bmd1 = new BitmapDrawable(); 
    bmd1 = (BitmapDrawable) res.getDrawable(R.drawable.blue); 
    imgView1.setImageDrawable(bmd1); 
spec = tabHost.newTabSpec("firsttab").setIndicator(imgView1) 
.setContent(intent); 
tabHost.addTab(spec); 

    intent = new Intent().setClass(this, AlbumsActivity.class);  
    ImageView imgView2 = new ImageView(this); 
    BitmapDrawable bmd2 = new BitmapDrawable(); 
     bmd2 = (BitmapDrawable) res.getDrawable(R.drawable.pink); 
     imgView2.setImageDrawable(bmd2); 
     spec = tabHost.newTabSpec("secondtab").setIndicator(imgView2) 
     .setContent(intent); 
     tabHost.addTab(spec); 

    intent = new Intent().setClass(this, SongsActivity.class);  
    ImageView imgView3 = new ImageView(this); 
     BitmapDrawable bmd3 = new BitmapDrawable(); 
      bmd3 = (BitmapDrawable) res.getDrawable(R.drawable.purple); 
      imgView3.setImageDrawable(bmd3); 
      spec = tabHost.newTabSpec("thirdtab").setIndicator(imgView3) 
      .setContent(intent); 
      tabHost.addTab(spec); 

      intent = new Intent().setClass(this, Forthtab.class);  
      ImageView imgView4 = new ImageView(this); 
       BitmapDrawable bmd4 = new BitmapDrawable(); 
        bmd4 = (BitmapDrawable) res.getDrawable(R.drawable.red); 
        imgView4.setImageDrawable(bmd4); 
        spec = tabHost.newTabSpec("forthtab").setIndicator(imgView4) 
        .setContent(intent); 
        tabHost.addTab(spec); 



    tabHost.setCurrentTab(0); 
} 

}

我能够得到我想要的任何选项卡位图,问题是我原来的位图太小,看,有一次我增加了他们大小的标签最终在屏幕中间有一个巨大的空白黑色空间。当我点击黑色空间时,它会相应地更改标签。有没有办法将它放回顶部并使每个位图填充选项卡?

回答

0

我能找到一个临时解决方案。我基本上保持代码完全一样,但玩了我的图像文件。我将位图图片更改为PNG文件,但重要的是指南here看起来像Android系统有一个非常敏感的选项卡图标系统。正如我所说这是一个临时解决方案,我打算更多地使用它。

我现在需要帮助的唯一方法是使用标签连接,在Google推荐的48 x 48px作品设置中使用png图标,但标签图标并未触及。寻找解决方案让他们接触,让他们彼此紧挨着。

相关问题