Android學習筆記(五) 之android tabwidget 調整高度文字居中

處理如下:

[java]
<span style="font-size:18px;color:#3333ff;">  TabWidget tabWidget = tabHost.getTabWidget(); 
             
            for (int i = 0; i < tabWidget.getChildCount(); i++) { 
                  View child = tabWidget.getChildAt(i); 
 
                 final TextView tv = (TextView)child.findViewById(android.R.id.title); 
                 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams(); 
                 params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底邊對齊 
                 params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //設置文字居中對齊 
}</span> 

 

但是這樣高度不協調,然後需要調整高度,再更改代碼

[java]
<span style="font-size:18px;color:#3333ff;">  TabWidget tabWidget = tabHost.getTabWidget(); 
             
            for (int i = 0; i < tabWidget.getChildCount(); i++) { 
                  View child = tabWidget.getChildAt(i); 
 
                 final TextView tv = (TextView)child.findViewById(android.R.id.title); 
                 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams(); 
                 params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底邊對齊 
                 params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //設置文字居中對齊 
                  
                 child.getLayoutParams().height = 30; 
 
//               final ImageView iv = (ImageView)child 
//                         .findViewById(android.R.id.icon); 
//                  iv.getLayoutParams().height = 0; 
 
             } 
</span> 

 
 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *