2011-01-09 13 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アイコンを使用してタブを接続していますが、タブアイコンは触れていません。彼らが互いに触れるようにするソリューションを探して、彼らは互いに隣り合っています。

関連する問題