Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android學習筆記(五) 之android tabwidget 調整高度文字居中

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

編輯:關於Android編程

處理如下:

[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> 

 
 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved