2016-04-30 10 views
1

今、固定高さで作っています。ここに私のコードです。下のタブバーに動的な高さを与えますか?

この高さを画面解像度に応じて動的にしたいと考えています。

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) 
{ 
    tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 130; 
    if (i == 0) 
    { 
    tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff")); 
    } 
    else 
    { 
    tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE); 
    } 
} 

答えて

2

私は私の質問

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) 
     { 
      // Log.e("Selcted : ", ""+i); 
      tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = getHeight(getApplicationContext()); 
      if (i == 0) 
      { 
       tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff")); 
      } 
      else 
      { 
       tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE); 
      } 
     } 

のためのソリューションは、以下の方法からの高さを取得し、あなたがあなたのタブバーのための完全な高さを取得します発見しました。

public int getHeight(Context context) 
    { 
    Resources resources = context.getResources(); 
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); 
if (resourceId > 0) 
{ 
return resources.getDimensionPixelSize(resourceId); 
} 
return 0; 
} 
関連する問題